Win a copy of Java Persistence with Spring Data and Hibernate this week in the Spring forum!
  • 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
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

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
 
What are you doing? You are supposed to be reading this tiny ad!
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic