• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

rollback() vs setRollbackOnly()

 
Ranch Hand
Posts: 344
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For BMT bean, we have rollback() and setRollbackOnly(). Actuall, why we need both, while both are used to rollback the transaction?
Is there any differences is there between rollback() and setRollbackOnly()
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A BMT bean does not (must not) call setRollbackOnly()
 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Think again...
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
BMT and CMT both can call setRollbackonly, the only difference is that BMT should call it on UserTransaction where as CMT should call on it's context. It will be useful only when there is multiple component inlvolves in single transaction and you would like to do transaction commit or rollback based on other component outcome.

Example :

UserTransaction ut = context.getUserTransaction();
ut.begin;
OtherComponent oth = new OtherComponent();
oth.doStuff(ut);
if(ut.getStatus() == javax.transaction.Status.STATUS_MARKED_ROLLBACK) {
ut.rollback();
}
else
{
do some processing
ut.commit;
}

//OtherComponent

public void doStuff(UserTransaction ut){
do processing1
if(something went wrong){
ut.setRollbackOnly();
}
else{
do processing 2
}
}

Though above things can be achieved using proper exception handling instead of using setRollbackOnly.

Regards,
Rajan

[ May 31, 2007: Message edited by: rajan singh ]
[ May 31, 2007: Message edited by: rajan singh ]
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oops, sorry gives, I misunderstood UserTransaction.setRollbackOnly and EJBContext.setRollbackOnly
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oops, sorry guys, I misunderstood UserTransaction.setRollbackOnly and EJBContext.setRollbackOnly
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic