This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Transaction rollback question

 
Joe Harry
Ranch Hand
Posts: 10091
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Joe Harry
Ranch Hand
Posts: 10091
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any ideas!
 
Ralph Jaus
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Joe Harry
Ranch Hand
Posts: 10091
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my Stateless Session Bean, I do not have any PreDestroy callbacks. Anyways thanks for the suggestion.
 
Joe Harry
Ranch Hand
Posts: 10091
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic