This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes EJB and other Java EE Technologies and the fly likes CMT Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "CMT" Watch "CMT" New topic
Author

CMT

Johnson Tmmet
Greenhorn

Joined: Oct 27, 2005
Posts: 8
Hi,
I have a stateless session bean with Container Managed Transaction.
In my ejb method, I call DAO class and the DAO class performs databas e operation.SQLException and Exception were caught in DAO class methods and thrown as application exception,DAOException.
My question is "Will the EJB container still able to rollback the transaction when an exception occured as the DAO method catches Exception also? That is, is it ok to catch Exception in class methods called from EJB method?
Thanks in advance,
Valentin Tanase
Ranch Hand

Joined: Feb 17, 2005
Posts: 704
Hi Johnson,

Let start with this one:

That is, is it ok to catch Exception in class methods called from EJB method?

It certainly is.

Will the EJB container still able to rollback the transaction when an exception occured as the DAO method catches Exception also?

It depends. If your exception is a system exception (extends the RuntimeException) then you�re safed, the container will rollback the transaction for you. Otherwise, if your exception is a checked exception then you have to rollback the transaction yourself (the container will give the client one more chance to recover and probably retry the transaction). You can do this catching the exception as usual. In the catch block however you must call the setRollbackOnly method on the session context object and rethrow an application specific exception.
Regards.


I think, therefore I exist -- Rene Descartes
 
jQuery in Action, 2nd edition
 
subject: CMT