Java - JPA - When we need more than one EntityManager?
- by Yatendra Goel
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?