Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Transaction rolledback, Singleton's variables won't rollback

Posts: 1924
  • 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( ...

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

What a stench! Central nervous system shutting down. Save yourself tiny ad!
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic