• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception handling - regarding

 
Sub swamy
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Greg Charles
Sheriff
Posts: 3002
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sub swamy
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sub swamy
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got it clarified - Page 356 of spec.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic