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 ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

persistence context propagation from a stateful bean in a JTA transaction

 
Bartender
Posts: 1924
13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, on p. 295 of specification about persistence context:


If the component is a stateful session bean to which an extended persistence context has been
bound and there is a different persistence context bound to the JTA transaction, an EJBException
is thrown by the container.



I modified txScopedPersistenceContext example in the JPA Pro:





The employee service stateful bean's persistence context is in a JTA transaction (CMT). But when the audit service's logTransaction2 is called, a different persistence context associated with the audit service bean is bound to the same JTA.
At first, I thought the audit service will throw an exception as described by the quote.
But why it does not ?
 
Himai Minh
Bartender
Posts: 1924
13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I can answer my own question after I read the following Hibernate document:


If a stateful session bean with an extended persistence context calls a stateless session bean or a stateful session bean with a transaction-scoped persistence context in the same JTA transaction, the persistence context is propagated.



In the above case, the employee service bean with extended persistence context calls the audit service bean with a transaction pc in the same JTA, it works.
Reference:
https://access.redhat.com/documentation/en-US/JBoss_Enterprise_Application_Platform/4.2/html/Hibernate_EntityManager_User_Guide/sect-Hibernate_EntityManager_User_Guide-EJB_container_environment-Persistence_context_propagation.html
 
Creator of Enthuware JWS+ V6
Posts: 3348
303
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

In the above case, the employee service bean with extended persistence context calls the audit service bean with a transaction pc in the same JTA, it works.  


Correct, in other words: the Stateless Session Bean will use the same PersistenceContext as the Stateful Session Bean -> it is propagated by the container (same JTA transaction).
 
    Bookmark Topic Watch Topic
  • New Topic