• Post Reply Bookmark Topic Watch Topic
  • New Topic

Transaction rolledback, Singleton's variables won't rollback

Himai Minh
Ranch Hand
Posts: 1400
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found out that when a transaction is rollback and the bean throws EJBTransactionRolledBackException to clients, the bean's variable is not rollback.
I guess the rollback only applied to the data related to the EntityManager.


Bean B which is a singleton. It injects an integer 10, set it to 20. But it throws MyException which is a system exception.

Bean A is the client of Bean B. Bean B's MyException is propagated to Bean A. Bean A throws EJBTransactionRollbackException

The servlet that calls Bean A gets the EJBTransactionRollbackedException.
But at the end, Bean B's integer is still 20.

Info: The originial integer is :10
Info: The integer is now :20

Warning: A system exception occurred during an invocation on EJB BeanB method public void com.ivan.scbcd6.BeanB.myIncorrectMethod()
javax.ejb.TransactionRolledbackLocalException: Exception thrown from bean
Caused by: com.ivan.scbcd6.MyException
Warning: A system exception occurred during an invocation on EJB BeanA method public void com.ivan.scbcd6.BeanA.myWrongMethod()
Caused by: com.ivan.scbcd6.MyException
at com.ivan.scbcd6.BeanB.myIncorrectMethod(BeanB.java:25) ...

Info: Bean A gets EJBException as Bean B's transaction is marked rollback
Severe: javax.ejb.EJBTransactionRolledbackException ....Caused by: com.ivan.scbcd6.MyException ...

//The transaction is marked for rollback by the container, but the integer that has been set to 20 is still 20.
Info: Bean B's integer after rollback: 20
Hot dog! An advertiser loves us THIS much:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!