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,
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.