user623258
user623258

Reputation: 11

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 trying to commit the transaction?

Thanks!

Upvotes: 1

Views: 1616

Answers (2)

Heiko Rupp
Heiko Rupp

Reputation: 30944

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.

Upvotes: 0

LeChe
LeChe

Reputation: 1286

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...

Upvotes: 3

Related Questions