• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

setRollBackOnly() not working

 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a stateless session bean and from the method i am calling a POJO which updates 2 different tables.
In event of an exception i am calling the setRollBackOnly() method on the context in the ejb.
The problem is that if an exception occurs during the update of the 2nd table the rollback does not haapens as the data gets updated in the 1st table whereas it shud not get updated as an exception has occured.
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you configured a TxDataSource?

What is the value of the <trans-attribute> elemnt for your EJB method? (I am assuming you have a CMT bean.)
 
Gavi Raaghav
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It works fine when i specify <trans-attribute>Required</trans-attribute> for the method. But i was thinking that setRollBackOnly() will be enough to rollback.
Whats the importance of each of these 2 while doing a rollback?
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The setRollbackOnly method only works in a transaction. If you fail to specify <trans-attribute>Required</trans-attribute>, the container will assign a default value, maybe NotSupported. In other words, the method will run in an unspecified transaction context which in your case means not running in a transaction. If the caller is part of a transaction, then the caller's transaction is suspended. If the EJB method fails, there will be no effect on the caller's transaction, and no rollback will occur.

Your case is a good example why transaction attributes must be specified for the appropriate methods of a CMT bean, as you may otherwise get an unwanted default attribute.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic