users@glassfish.java.net

Re: Putting EntityManagerFactory into JNDI

From: <glassfish_at_javadesktop.org>
Date: Wed, 23 Jan 2008 07:49:54 PST

The lookup call that I posted can be done anywhere, including several calls below. You could wrap it up in a utility class somewhere. The ENC JNDI is available from any call that is invoked on the EJB and any calls that that method makes. So as long as your initial entry point is through and EJB that is annotated or has an a persistence-unit-ref in the ejb-jar.xml, it will work.

What is an issue (and you probably know this) is that the EntityManager injected into a EJB has its lifecycle managed by the container. You do not control the transactions and you do not need to cleanup afterwards either.

A question as well. If you want to add a global JNDI entry, you must have some central place that you are going to do that from. What kind of environment is that?

I also see that you want to inject the EntityManagerFactory. I am assuming that you are then going to control the transactions and cleanup, etc even while executing in the context of an EJB invocation. So the EntityManagerFactory and the EntityManager that you acquire from it is probably going to be much different than the one available in the EJB. If this is okay, why not just use the javax.persistence.Persistence API to acquire the EntityManagerFactory and dispense with using the JNDI?
[Message sent by forum member 'bbergquist' (bbergquist)]

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