users@glassfish.java.net

Re: Putting EntityManagerFactory into JNDI

From: <glassfish_at_javadesktop.org>
Date: Wed, 23 Jan 2008 11:17:43 PST

I'm a little dense, I admit that, but just what are you going to annotate to get Glassfish to inject a reference to the EntityManagerFactory. It's got to be a managed component or the annotation will not be processed. The annotation is for the managed component and defines a reference or an injected object for that management component as the annotation is on or in the managed component class. The same goes when using the xml descriptor as those references or injections are always contained within a managed component declaration. I don't know of any place where a global reference can be made without it being in or on a managed component.

But say you can find a place to annotate and this was something like a remote EJB, you would use the "mappedName" attribute of the annotation to register the entity into the global JNDI. Unfortunately the @PersistenceUnit annotation does not have that capability.

So I guess I'm still unclear on how you say that Glassfish "creates" the EMF for you. Where in your application does Glassfish create this and how do you get a hold of it?

From an EJB point of view, the EntityManagerFactory (and EntityManager) are available when inside the EJB, but I cannot find anywhere that it is specified where it is "created".

I was thinking may you could do this. Since you probably have a starting point class, could you use "Persistence.createEntityManagerFactory", and then register this within the global JNDI yourself under your own context? Then anywhere else you could use JNDI to look it up. But then I looked at the EntityManagerFactory interface and it does not seem to specify that the EntityManagerFactory be serializable or referenceable so I don't know if you can store an EntityManagerFactory instance in the global JNDI.

Sorry I don't have a better answer but I'm just trying to think and help if possible.
[Message sent by forum member 'bbergquist' (bbergquist)]

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