File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Transaction rollback...and being user friendly Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Transaction rollback...and being user friendly" Watch "Transaction rollback...and being user friendly" New topic
Author

Transaction rollback...and being user friendly

alzamabar
Ranch Hand

Joined: Jul 24, 2002
Posts: 379
When a transaction rolls back the client receives the equivalent of a runtime exception. This means that, like any runtime exception (uncaught), usually the stack trace will appear on the console, or the application will stop working. For instance, when I get a NullPointerException for my application (which is a runtime exception), I get the stack trace of what happened (like: something bad happened). This is fine for CMT, as it's the container which manages transactions (unless the bean's developer can force it to rollback), and if it decides to rollback a transaction it's probably because something bad happened; but BMT, it's be bean developer who has got complete control over transaction behaviour, and if a rollback is thrown, this doesn't mean necessarily that something bad as a runtime exception occurred. The bean developer may decide to rollback a transaction if he realizes for instance that there were no enough funds in a bank account: now, is this a reason enough to throw the equivalent of a system exception?


Marco Tedone<br />SCJP1.4,SCJP5,SCBCD,SCWCD
Nitin Mehhta
Ranch Hand

Joined: May 18, 2004
Posts: 48
Hi,
In case of a BMT if there is a situation where you need to just rollback the transaction then you can call setRollBackOnly in the code and probably throw an application specific exception, which would be more useful in you application and you can set up the client to expect the exception and do the appropriate things instead of crashing down the bean by a system exception. I hope I answered your question.
Severin Stoeckli
Ranch Hand

Joined: Jul 21, 2004
Posts: 62
Hi Marc,

If I understood your question right you expect a "TransactionRolledBackException" in each case the transaction rolls back. That's not true. Even for CMP, the spec in 18.3.6 says:

However, the Container should not throw the java.rmi.RemoteException or
javax.ejb.EJBException if the Container performs a transaction rollback because the instance
has invoked the setRollbackOnly() method on its EJBContext object. In this case, the Container
must rollback the transaction and pass the business method result or the application exception
thrown by the business method to the client.


So it is possibel to rollback a transaction without exception. Or did I undestand you wrong?

Severin
alzamabar
Ranch Hand

Joined: Jul 24, 2002
Posts: 379
Originally posted by Severin St�ckli:
Hi Marc,

If I understood your question right you expect a "TransactionRolledBackException" in each case the transaction rolls back. That's not true. Even for CMP, the spec in 18.3.6 says:

However, the Container should not throw the java.rmi.RemoteException or
javax.ejb.EJBException if the Container performs a transaction rollback because the instance
has invoked the setRollbackOnly() method on its EJBContext object. In this case, the Container
must rollback the transaction and pass the business method result or the application exception
thrown by the business method to the client.


So it is possibel to rollback a transaction without exception. Or did I undestand you wrong?

Severin



Thank you Severin, this is exactly the answer that I was looking for.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Transaction rollback...and being user friendly
 
Similar Threads
how to choose between EJBException and Application Exception?
Application Exception thrown by Bean with BMT
Rollback
Enthuware Question doubt
Transaction Rollback not rolling back the Database updates !!