File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EntityManager question

 
Khaled Mahmoud
Ranch Hand
Posts: 361
  • 0
  • Mark post as helpful
  • send pies
  • 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 ]
 
Shivani Chandna
Ranch Hand
Posts: 380
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean when you say a level of coordination?

Regards.
 
Camilo Morales
Ranch Hand
Posts: 92
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually i had a confusion about
of the meaning of persistence context but it is now clear.

Thank you.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic