users@glassfish.java.net

Re: How to inject EntityManager dynamically (runtime)

From: <glassfish_at_javadesktop.org>
Date: Tue, 22 Jan 2008 12:24:02 PST

There are several problems with your approach:
1. Somehow persistenceUnitName that you pass around changed from "ejbPU1" (that exists) to "ejbPU" (that doesn't).

2. There is a big difference in what would be happening in terms of transactions and persistence context when you inject or look up an EM (or EMF) and when you call Persistence.createEntityManagerFactory(persistenceUnitName). JTA transactions won't affect your EMs any more, and even datasource lookup can depend on the provider's code.

You can either dynamically look up the correct EM or dynamically choose one of 2 injected EMs.

Regards,
-marina
[Message sent by forum member 'mvatkina' (mvatkina)]

http://forums.java.net/jive/thread.jspa?messageID=255200