Win a copy of Spark in Action this week in the Open Source Projects 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() and setRollbackOnly()

 
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
There are two methods to roll back a transaction in the javax.transaction.UserTransaction interface.
It seems to me that both rollback() and setRollbackOnly() will roll back the transaction. What is the difference between them, and when shold I use rollback() and when setRollbackOnly()?


------------------
Thanks,
Mike
 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
if you use the UserTransaction (Bean Managed Transaction, not possible with Entitiy Beans), you can roolback this transaction
using rollback().
If you use Container Managed Transaction ( Session and Entity)
you have to mark the Transaction as to be rollbacked using
setRollbackOnly() in order to rollback this transaction.
------------------
Marco Barenkamp
____________________________________________
L M I N T E R N E T S E R V I C E S AG
Senior Trainer & Architect,
BEA Certified Enterprise Developer
Sun Certified Programmer for the Java2 Platform
Sun Certified Web Component Developer for the Java2 Platform
Sun Certified Developer for the Java 2 Platform
Sun Certified Enterprise Architect for the Java 2 Platform Enterprise Edition (PI)
 
Mike Yu
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Marco,
Your reply is really usefull. However, I have a further question about this issue:
In a Container-Managed transaction, we have to call setRollbackOnly() method on an object of EJBContext interface. The setRollbackOnly() of the UserTransaction interface is not allowed in a Container-Managed transaction. Then, what is The setRollbackOnly() of the UserTransaction interface uesed for?

------------------
Thanks,
Mike
 
Acetylsalicylic acid is aspirin. This could be handy too:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic