EJB 2.1不保存jboss 6.3中方法调用的状态 [英] EJB 2.1 doesn't preserve state across method calls in jboss 6.3

查看:122
本文介绍了EJB 2.1不保存jboss 6.3中方法调用的状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在从jboss 4迁移到jboss 6.
Out系统有大量的EJB 2.1 bean。一旦我们在jboss 6中部署了应用程序,bean就会停止在方法调用中保持状态。



这是正常吗?如果没有,可以做些什么来克服这个问题?



编辑:2015.08.04



Bean:Stateful



我希望我可以分享src代码,但公司有非常严格的政策。



任何从您的经验中获得的指导或指示就足够了。



更多信息 / p>

方案:用户更新员工记录。



系统有一个AbstractController,它执行单个记录更新。控制器查找该bean并检索该句柄。
然后,使用反射检索方法名称。
然后将一个标志'isDirty'设置为true(bean中的setter)



然后,控制器将遍历通过调用EJB存储库更新每个字段的方法名称方法。在运行更新语句之前的存储方法中,检查标志'isDirty'。



在jboss 4中,该标志保持为true,但是当我们迁移到6 ,这个标志开始回到假。



FYI:这是传统的来源,我真的希望我可以改变逻辑,但我不能。



更新:2015.08.04:3pm



我在ejb激活和钝化方法中放置了一个断点。豆类被激活后立即被钝化。继续我的调查将更新此线程。



更新:2015.08.20
我根据EJB规范构建了一个示例应用程序,并运行它在jboss 5.1和6.3中



这两个实例是相同的。在方法调用之间,实体bean丢失它的状态

  bean.doSomething(); 
bean.doSomethingElse();

结果

  setEntityContext(EntityContext ctx)被调用---标志值-false 
ejbCreate()被调用---标志值-false
ejbPostCreate()被调用--- Flag Value-false
ejbPassivate()被调用---标志值-false
unsetEntityContext()被调用---标志值-false
setEntityContext(EntityContext ctx)被调用---标志值 - false
ejbActivate()调用---标志值-false
ejbLoad()调用---标志值-false
[EmailConfigBean] doSomething被调用.---标志值更新为true
ejbStore()被调用---标志值 - 真
ejbPassivate()被调用---标志值 - 真
unsetEntityContext()被调用---标志值 - 真
setEntityContext (EntityContext ctx)调用--- Flag Value-false
ejbActivate()被调用---标志值-false
ejbLoad()被调用---标志值-false
[EmailConfigBean] doSomethingElse调用.--- int值更新为-10
ejbStore()调用--- F1 ag Value-false
ejbPassivate()被调用---标志值-false
unsetEntityContext()被调用---标志值-false

进一步挖掘,我读了这个



Bean Provider可以使用实例变量来存储依赖于
实体bean实例的持久状态,虽然不鼓励使用。 Bean Provider应该使用ejbLoad
方法来重新同步依赖于实体bean持久性
状态的任何实例变量的值。一般来说,任何取决于实体bean的持久状态的非持久状态应在ejbLoad方法中重新计算



换句话说,你有责任在ejbLoad中将isDirty设置为正确的状态
你不应该期望它保留从一个调用到下一个调用的任何特定值 - 如果是这样,它只是因为
的一个特定的实施或意外。

解决方案

经过很长时间,我想出了这个行为的原因。
$ b

基本上,在jboss 6.3中,他们只支持提交选项3。



什么是提交选项?
这是我们在事务提交时对实体bean状态的控制。



什么是commit-option 3?
池化bean:事务,实例和状态都不是有效的(实例将被钝化并返回到池)。每个客户端调用基于6.3的迁移指南,导致ejbActivate,ejbLoad,然后是业务方法,然后ejbStore和ejbPassivate





在JBoss EAP 5.x中,还可以自定义缓存,池,提交选项,
和拦截器堆栈。在JBoss EAP 6中,这是不可能的。只有一个
实现,它类似于每个事务实例Inst $政策
提交选项C



谢谢你们所有的支持 - 希望我的问题有助于其他noobs被困在类似的问题。和平


We are in the process of migrating from jboss 4 to jboss 6. Out system has a ton of EJB 2.1 beans. Once we deployed the application in jboss 6, the beans stopped preserving state across method calls.

IS this normal? if not, what can be done to overcome this problem?

Edit:2015.08.04

Bean: Stateful

I wish i could share src code but, the company has very strict policies.

Any guidance or direction from your experience would suffice.

More info

Scenario: user updates a employee record.

The system has a AbstractController which does single record updates. The controller looks up the bean and retrieves the handle to it. Then, using reflection it retrieves the method names. Then sets a flag 'isDirty' to true (setter inside the bean)

The controller then iterates over the method names updating each field by calling the EJB store method. Within the store method before the update statement is run the flag 'isDirty' is checked.

In jboss 4 this flag remains as 'true', but when we migrated into 6, this flag started to reverting back to false.

FYI: This is legacy source, and i really wish i could change the logic, but i cant.

Update: 2015.08.04: 3pm

I placed a break point in the ejb activate and passivate methods. The beans are being passivated immediately after they are activated. continuing my investigation. Will keep this thread updated.

Update: 2015.08.20 I built a sample application according to the EJB spec and ran it in both jboss 5.1 and 6.3

The two instances were identical. between method calls, the entity bean loses its state

bean.doSomething();
bean.doSomethingElse();

results

setEntityContext(EntityContext ctx) invoked --- Flag Value-false
ejbCreate() invoked --- Flag Value-false
ejbPostCreate() invoked --- Flag Value-false
ejbPassivate() invoked --- Flag Value-false
unsetEntityContext() invoked --- Flag Value-false
setEntityContext(EntityContext ctx) invoked --- Flag Value-false
ejbActivate() invoked --- Flag Value-false
ejbLoad() invoked --- Flag Value-false
[EmailConfigBean] doSomething invoked.--- Flag Value Updated to-true
ejbStore() invoked --- Flag Value-true
ejbPassivate() invoked --- Flag Value-true
unsetEntityContext() invoked --- Flag Value-true
setEntityContext(EntityContext ctx) invoked --- Flag Value-false
ejbActivate() invoked --- Flag Value-false
ejbLoad() invoked --- Flag Value-false
[EmailConfigBean] doSomethingElse invoked.--- int Value Updated to-10
ejbStore() invoked --- Flag Value-false
ejbPassivate() invoked --- Flag Value-false
unsetEntityContext() invoked --- Flag Value-false

Did some further digging and i read this

"The Bean Provider can use instance variables to store values that depend on the persistent state of the entity bean instance, although this use is not encouraged. The Bean Provider should use the ejbLoad method to resynchronize the values of any instance variables that depend on the entity bean’s persistent state. In general, any non-persistent state that depends on the persistent state of an entity bean should be recomputed during the ejbLoad method."

In other words, you are responsible for setting "isDirty" to the correct state during ejbLoad. You should not expect it to retain any specific value from one call to the next – if it does, it's only because of a specific implementation or by accident.

解决方案

After a long while, i figured out the reason for this behavior.

Basically, in jboss 6.3 they have only support for commit-option 3.

What is a commit-option? It is the control we have on the entity beans state at transaction commit time.

what is commit-option 3? "Pooled bean: At the end of the transaction, neither the instance nor its state is valid (instance will be passivated and returned to the pool). Every client call causes an ejbActivate, ejbLoad, then the business method, then ejbStore, and ejbPassivate"

based on the migration guide for 6.3

"In JBoss EAP 5.x, it was also possible to customize caching, pooling, commit-options, and the interceptor stack. In JBoss EAP 6, this is no longer possible. There is only one implementation, which is similar to the Instance Per Transaction policy with commit-option C"

Thank you guys for all the support - hope my question helps out other noobs stuck on a similar issue. peace

这篇关于EJB 2.1不保存jboss 6.3中方法调用的状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆