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 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
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: CMT