Java - JPA - When we need more than one EntityManager?

Posted by Yatendra Goel on Stack Overflow See other posts from Stack Overflow or by Yatendra Goel
Published on 2010-04-06T16:44:45Z Indexed on 2010/04/06 16:53 UTC
Read the original article Hit count: 404

Filed under:
|

I am learning JPA and have one question:

In which situations we need more than one EntityManager in our application?

The two situations that I am aware of are as follows:

  • When our application is a multi-threaded application and more than one thread needs JPA transaction because EntityManager is not thread-safe and we need one EntityManager per thread.

  • When any of the thread needs multiple concurrent transactions, we need more than one EntityManager in that thread because there is one-to-one relationship between EntityManager and EntityTransaction.

Q1. Are there any other situations when we need more than one EntityManager?

=================================================================================

Q2. Upto my understanding, there should be only one EntityManagerFactory per Persitence Unit. Am I correct? If not, then what are those situations when we need multiple EntityManagerFactory per Persistence Unit?

© Stack Overflow or respective owner

Related posts about java

Related posts about jpa