• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

CMT setRollbackOnly(), RollabackException

 
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[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 ??
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
 
Ranch Hand
Posts: 608
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ....

 
reply
    Bookmark Topic Watch Topic
  • New Topic