• Post Reply Bookmark Topic Watch Topic
  • New Topic

setRollBackOnly() not working

 
Gavi Raaghav
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • 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.
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!