File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

CMT

 
Johnson Tmmet
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 704
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic