Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

rollback() vs setRollbackOnly()

 
Ranch Hand
Posts: 344
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
A BMT bean does not (must not) call setRollbackOnly()
 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Think again...
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
Oops, sorry guys, I misunderstood UserTransaction.setRollbackOnly and EJBContext.setRollbackOnly
 
knowledge is the difference between drudgery and strategic action -- tiny ad
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic