One of the choices marked as correct that i came across in ejbcertificate.com was "..If the bean method throws an application exception but does not mark the transaction for rollback, the container will commit the transaction before re-throwing the application exception to the client..." - is the above statement correct ? Thought, HFEJB says that in case of application exceptions, the container would throw the exception as such to the client.
I'm not sure where you see the conflict there. Application exceptions do not cause an automatic rollbac. If the container started a transaction for the method, it will commit that transaction unless the bean code marked the transaction as rollback only before it threw the exception. In that case, the container will rollback the transaction. Either way, it will rethrow the exception back to the client.
If the container didn't start the transaction, but just used the one the client started, then it won't roll it back.
If a bean's method is running in a transaction, then that transaction must complete before the method ends. As the throwing of the application exception causes the method to end, the container must end (commit) the transaction before the exception is rethrown to the client.
If a system exception were thrown by the bean, the container must end (rollback) the transaction before throwing RemoteException or EJBException to the client.
SCJP 1.4, SCWCD 1.3, SCBCD 1.3
Joined: Oct 02, 2002
Thanks Greg and Roger.
Just to add on to this - for a BMT method we are expected to commit or rollback a transaction before the method ends. So, incase of a BMT method (MDB/stateless session bean) when we do not commit or rollback a transaction in code, can we assume that the container would commit the transaction when we assume that there is no exception being thrown.