• 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

Transaction rolledback, Singleton's variables won't rollback

 
Bartender
Posts: 2419
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

ejb-jar.xml


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()
javax.ejb.EJBTransactionRolledbackException
....
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

 
reply
    Bookmark Topic Watch Topic
  • New Topic