This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Transaction rollback question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Transaction rollback question" Watch "Transaction rollback question" New topic
Author

Transaction rollback question

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9345
    
    2

Guys

In one scenario, I'm using EJB 3 SSB's talking to a JDBC layer to insert and read data. I'm using the default Transaction attribute which it Required on the SSB. Now when and how could my transaction rollback? I want the transaction to rollback when my JDBC inserts throw an SQLException. What I have to do is catch the SQLException in my JDBC layer and rethrow a RuntimeException which will propogate to my Session Bean. Would this suffice for the transaction to rollback?



So is the above one just enough for the transaction to rollback in case of an SQLException?


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9345
    
    2

Any ideas!
Ralph Jaus
Ranch Hand

Joined: Apr 27, 2008
Posts: 342
If MyRuntimeException isn't declared as application exception, this will lead to a rollback. However, I don't think this is a good solution in general, because the bean instance will be discarded and pre destroy methods aren't executed. Using setRollbackOnly() in myMethod seems to be a better alternative to me.


SCJP 5 (98%) - SCBCD 5 (98%)
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9345
    
    2

In my Stateless Session Bean, I do not have any PreDestroy callbacks. Anyways thanks for the suggestion.
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9345
    
    2

So if the Container discards the bean instance (for a Stateless session bean) what happens to the instance pool of Stateless beans the Container maintains? would it be recreated? or how does the Container manages such a situation?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Transaction rollback question
 
Similar Threads
How do Container Managed Transactions work?
connection rollback/ atomic transaction problem
Threading and Exceptions.
Transaction handling in Session Bean
Transactions with Stored Procedures