aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes CMT setRollbackOnly(), RollabackException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "CMT setRollbackOnly(), RollabackException" Watch "CMT setRollbackOnly(), RollabackException" New topic
Author

CMT setRollbackOnly(), RollabackException

Sandeep Vaid
Ranch Hand

Joined: Feb 27, 2006
Posts: 390
[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 ??
Manuel Alberto Quero
Ranch Hand

Joined: Jul 17, 2009
Posts: 31
Hello,

a) I agree with you with, the container does not throw any exception.

bi) Yes, if you set the appropiate transaction attribute.

bii) The container will just mark the transaction to be rolledback so the client that initiated the transaction (e.g. another ejb, a servlet) has to manage the transaction. Some code like this needs to be added to the client:

if (utx.getStatus() == Status.STATUS_MARKED_ROLLBACK) {
utx.rollback();
}
else {
utx.commit();
}

Hope this helps,

Manuel
Sandeep Vaid
Ranch Hand

Joined: Feb 27, 2006
Posts: 390
Sandeep Vaid wrote:[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."

b) ii) According to the statement "CONTIANER WILL ROLLBACK THE TRANSACTION" is contradictory..
Your code looks logical.. I also thought the same way.. but the statement confused me.
Another case may occur:
b) iii) A CMT Method1 calls another CMT method2. method2 calls setRollBackOnly. Now container will only mark.. method2 ends still no rollback occcurs. Method1 ends and now container will rollback the transaction.. Right ?
Manuel Alberto Quero
Ranch Hand

Joined: Jul 17, 2009
Posts: 31
bii) I have tested this by using a servlet as a client and an EJB and it works as we expect, i.e. the container does not rollback the transaction (the client is reponsible for commit/rollback by using the UserTransaction interface)

biii) Yes, as long as method1 and method2 share the same transactional context (i.e. method2 cannot use transactional attributes REQUIRES_NEW, NOT_SUPPORTED or NEVER)
Duran Harris
Ranch Hand

Joined: Nov 09, 2008
Posts: 598

Can anyone confirm this:

A BMT is started in BeanA.
BeanA invokes BeanB's method that has a transaction attribute of REQUIRED.
BeanB throws a system exception and the container rolls back it's transaction.

What happens to BeanA's transaction..EJb3 in Action says it gets rolled back and a RollBackException is returned to the client...but surely this doesnt apply to this situation?

I'd imagine it would work if BeanA used a CMT ....


===>SCJP 1.5(72%)<===
==>SCWCD1.5(76%)<===
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: CMT setRollbackOnly(), RollabackException
 
Similar Threads
CMT setRollbackOnly(), RollabackException
Question about transactions
question about BMT calling CMT
AutoAcknowledge Mode in MDB
ejbActivate and EntityContext