Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

persistence context propagation from a stateful bean in a JTA transaction

 
Ranch Hand
Posts: 1738
12
  • 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
Ranch Hand
Posts: 1738
12
  • 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: 3288
296
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).
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!