• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

EntityManager question

 
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have read in "EJB 3 In Action" is that entity manager is not thread safe. In EJB enterprise applications where many session beans use an entity manger reference i suppose that every thread gets its own reference of the entity manager object. My question is there a level of coordination between the entity manager instances.
[ August 19, 2007: Message edited by: Khaled Mahmoud ]
 
Ranch Hand
Posts: 380
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What do you mean when you say a level of coordination?

Regards.
 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure if I understand your question, anyway, refering to EntityManager operations take this into account:

There are 3 ways to get a reference to a EntityManager: Injection - JNDI lookup - EJBContext lookup. All of them create a NEW instance of the EntityManager (Injected or looked up), so every instance of the Session or Message Driven Bean get a NEW instance of the EntityManager. (there is no sharing of EntityManagers between components)

There is a special case where the SAME PersistenceContext attached to an EntityManager is propagated and used by two different STATEFUL SESSION BEAN instances. Is the following:

If one Stateful Session Beans with an EXTENDED Persistence Context is the Client of another Session Bean with an EXTENDED Persistence Context, in that case, and ONLY IF BOTH PERSISTENCE CONTEXTS WERE INJECTED, both Statefull Session Bean instances share the same persistence context in the scope of the transaction.

Take a look at the following link to the chapter 7 of Mikalai Zaikin notes and/or numeral 5.6.3.1 (page 122) of the EJB 3 Persistence Specification, where all the Container-Managed Persistence Contexts propagation cases are explained:

http://java.boot.by/scbcd5-guide/ch07s04.html

Hope this helps you,
 
Khaled Mahmoud
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually i had a confusion about
of the meaning of persistence context but it is now clear.

Thank you.
 
incandescent light gives off an efficient form of heat. You must be THIS smart to ride this ride. Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic