Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Transacation Behavior When Exceptions Are Thrown

 
Anthony Watson
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Scenario: a stateless session bean method (using container managed transactions) calls an update method on a DAO. The DAO calls a stored procedure that fails and a SQLException is thrown in the DAO. The DAO wraps the SQLException as a checked Exception called MyBusinessException. The stateless session bean method catches MyBusinessException, logs it, and returns (without ever calling setRollbackOnly() ).

In this scenario, won't the EJB container try to commit a transaction for a stored procedure that failed?
 
Marco Barenkamp
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, the container will commit the transaction. There is no
reason for the container not to commit it. How should the container
know that an exception has been thrown during execution of the stored
procedure.
The thing is: The DB will not have anything to commit (internally), so
that's not the important part.
but why don't you invoke setRollbackOnly(true) as that is the appropriate
action to take for the developer if he catches such an exception?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic