The moose likes EJB and Other Java EE Technologies and the fly likes rollback() and setRollbackOnly() Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » EJB and Other Java EE Technologies
Reply Bookmark "rollback() and setRollbackOnly()" Watch "rollback() and setRollbackOnly()" New topic
Author

rollback() and setRollbackOnly()

Mike Yu
Ranch Hand

Joined: Nov 17, 2001
Posts: 175
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


Thanks,<br />Mike
Marco Barenkamp
Ranch Hand

Joined: Aug 27, 2001
Posts: 94
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)


Marco Barenkamp<br />_ _ _ _ _ ________________________ _ _ _ _ _ <br />L M I N T E R N E T S E R V I C E S AG<br /> <br />Head of Software Development<br /> <br /> <br />BEA Certified Enterprise Developer<br />Sun Certified Programmer for the Java2 Platform<br />Sun Certified Web Component Developer for the Java2 Platform<br />Sun Certified Developer for the Java 2 Platform <br />Sun Certified Business Component Developer for the Java 2 Platform <br />Sun Certified Enterprise Architect for the Java 2 Platform Enterprise Edition<br /> <br />LMIS AG
Mike Yu
Ranch Hand

Joined: Nov 17, 2001
Posts: 175
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
 
 
subject: rollback() and setRollbackOnly()
 
Threads others viewed
using setRollbackOnly in BMT
Exceptions
Does the container call setRollbackOnly() method?
mock exam question
setRollBackOnly Doubt
MyEclipse, The Clear Choice