CatchSandeepVaid (23) [Avatar] Offline
#1
[P-189] of EJB3 In Action: "In case of transactions propagated from the client, if our method indicates that the transaction should be rolled back, the container
will not only roll back the whole transaction but will also throw a javax.transaction.RollbackException back to the client."

a) I tested this scenario, the container is not throwing RollbackException.Moreover nothing of this sort is written in EJB3 specs.
b) When will contianer rollback the transaction?? Here 2 cases can occur:
case i) When this method is NOT called from transactional client.. In this case the container mark the transaction to be rolledback (at the
statement where exception occurs) and will actully rollback transaction at method end.
case ii) When this method is called from transactional client. Suppose a BMT started a UserTransaction and called a CMT method,
In this case this CMT method will join the callers transaction. Now will the container simply marks the transaction to be rolledback and
the BMT method should check this flag and then only either rollback or commit the transaction ??
reza_rahman (456) [Avatar] Offline
#2
Re: CMT setRollbackOnly(), RollabackException
Sandeep,

CMT transactions do not participate in BMT transactions. The quote you have will happen when you have nested CMT transactions.

Hope it helps,
Reza
CatchSandeepVaid (23) [Avatar] Offline
#3
Re: CMT setRollbackOnly(), RollabackException
Reza,
CMT does participate in BMT.
Suppose i start a BMT and then call another bean's method which is marked for CMT, both can be part of single transaction..
However BMT won;t participate in CMT. Suppose i call a BMT from a CMT, then CMT will be suspended, BMT will start and finish and then CMT will be resumed.
reza_rahman (456) [Avatar] Offline
#4
Re: CMT setRollbackOnly(), RollabackException
Sandeep,

I'm not really sure what you are talking about. Try something like this:

@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void hit() {
context.setRollbackOnly();
}

You'll get a roll back exception on any Java EE 5 compliant server.

Hope it helps,
Reza
honeylibra (1) [Avatar] Offline
#5
Re: CMT setRollbackOnly(), RollabackException
hi i try your example but i never throw RollbackException
i am also reading ejb3 in action book
but this statement create problem for me

"In case of transactions propagated from the client, if our method indicates that the transaction should be rolled back, the container will not only roll back the whole transaction but will also throw a javax.transaction.RollbackException back to the client."

how should my method will indicates that transaction should be rollback. what i know is you can use setRollbackOnly(). but this does not send any exception client side .

please help to clarify this statement