1 Reply Latest reply on Jan 11, 2007 4:56 PM by jk;l jkl;

    Multiple EntityManagers

    jk;l jkl; Expert

      If you inject multiple EntityManagers into the same class with different persistence units, I assume that would allow for persisting objects to different databases within the same class.

      What I'm wondering about is the ability to inject multiple EntityManagers or EntityManagerFactory with the SAME persistence unit in the same class. What purpose might something like this hypothetically serve?

      I saw an example where one class had one injected EntityManager of a given persistence unit, and a created EntityManager (from EntityManagerFactory.createEntityManager() where the EntityManagerFactory has the same persistence unit).

      What purpose would either of these scenarios have...multiple EntityManagers (either injected directly or through the EntityManagerFactory) with the SAME persistence unit in one class?

      I'm confused on this issue because I can't see what the purpose of the same persistence unit would be...couldn't even guess...