Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code 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
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

persistence context propagation from a stateful bean in a JTA transaction

 
Ranch Foreman
Posts: 1897
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 Foreman
Posts: 1897
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: 3341
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).
 
Goodbye moon men. Hello tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic