aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Transacation Behavior When Exceptions Are Thrown Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Transacation Behavior When Exceptions Are Thrown" Watch "Transacation Behavior When Exceptions Are Thrown" New topic
Author

Transacation Behavior When Exceptions Are Thrown

Anthony Watson
Ranch Hand

Joined: Sep 25, 2003
Posts: 327
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

Joined: Aug 27, 2001
Posts: 94
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?


Marco Barenkamp<br />_ _ _ _ _ ________________________ _ _ _ _ _ <br />L M I N T E R N E T S E R V I C E S AG<br /> <br />Head of Software Development<br /> <br /> <br />BEA Certified Enterprise Developer<br />Sun Certified Programmer for the Java2 Platform<br />Sun Certified Web Component Developer for the Java2 Platform<br />Sun Certified Developer for the Java 2 Platform <br />Sun Certified Business Component Developer for the Java 2 Platform <br />Sun Certified Enterprise Architect for the Java 2 Platform Enterprise Edition<br /> <br />LMIS AG
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Transacation Behavior When Exceptions Are Thrown