开发者

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. The method() could set setRollbackOnly().

If the ejb method sets the setRollbackOnly(), should there be some checks before t开发者_Go百科rying to commit the transaction?

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.

BTW: make sure to call proxied methods if you specify a transaction attribute on a method. I.e., calling a method of an ejb which has a specific transaction attribute set from within the same ejb will not work as you expect...


the default setting of SLSB is the Tx semantics you describe.

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.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜