简体   繁体   English

具有CMT的Ejb3无状态bean

[英]Ejb3 stateless bean with CMT

Is it possible to have something like this? 可能有这样的事情吗? Client code in a thread with pseudo code : 带有伪代码的线程中的客户端代码:

transaction.begin();
ejb.method();
transaction.commit();

The method() belongs to an EJB3 stateless session bean, annotated with TransactionAttributeType.REQUIRED . method()属于EJB3无状态会话Bean,其注释为TransactionAttributeType.REQUIRED The method() could set setRollbackOnly() . method()可以设置setRollbackOnly()

If the ejb method sets the setRollbackOnly(), should there be some checks before trying to commit the transaction? 如果ejb方法设置了setRollbackOnly(),在尝试提交事务之前是否应该进行一些检查?

Thanks! 谢谢!

You could also set the transaction attribute on the called bean (method) to TransactionAttributeType.REQUIRES_NEW to force a new transaction on your method. 您还可以将被调用bean(方法)上的事务属性设置为TransactionAttributeType.REQUIRES_NEW以在您的方法上强制执行新事务。

BTW: make sure to call proxied methods if you specify a transaction attribute on a method . 顺便说一句:如果您在方法上指定了交易属性,请确保调用代理 方法 Ie, calling a method of an ejb which has a specific transaction attribute set from within the same ejb will not work as you expect... 即,从同一 ejb内调用具有特定事务属性设置的ejb的方法将无法按预期工作...

the default setting of SLSB is the Tx semantics you describe. SLSB的默认设置是您描述的Tx语义。

Manual rollback is possible by specifying EjbContext.setRollbackOnly() - this tells the Contaner (the 'C' in CMT) that it should not commit but toll back the Transaction. 通过指定EjbContext.setRollbackOnly()可以进行手动回滚-这告诉Contaner(CMT中的“ C”)它不应提交但应回扣事务。

If you want to completely set up the the transaction on your own, you can still mark the calling SLSB method as NotSupported and then inside manually open a Tx that you can forward to other SLSB calls. 如果您想完全自己设置事务,则仍可以将调用SLSB方法标记为NotSupported,然后在内部手动打开一个Tx,您可以将其转发给其他SLSB调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM