users@glassfish.java.net

Re: Putting EntityManagerFactory into JNDI

From: <glassfish_at_javadesktop.org>
Date: Wed, 23 Jan 2008 10:20:54 PST

> 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.

Sure, but since I can't predict which EJB the call will come through, this means that *every single* EJB in my app will have to be mindlessly annotated with a @PersistenceUnit, and this is exactly the thing I'd like to avoid.

> 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?

A Seam @Startup application-scoped component (it will be called from a servlet listener on application startup).

> 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.

Right, Seam will do it for me.

> If this is okay, why not just use the
> javax.persistence.Persistence API to acquire the
> EntityManagerFactory and dispense with using the JNDI?

Yes, but this is a workaround. Glassfish creates the EMF for me, why should I create my own? Isn't it easier to just have Glassfish bind the EMF it created to global JNDI?

And EMF is just a small part of the problem, another part (which everybody using Seam on Glassfish also complains about) is having to explicitly specify all EJBs Seam will use.

I know people have gotten away with specifying all the EJBs in ejb-local-refs in web.xml, but this didn't work for me in the case where Servlet calls EJB A, Seam injects EJB B into it, and while doing so it tries to inject EJB C into EJB B. My understanding of the problem is that the injection seems to happen in the context of EJB A since it's the EJB actually being invoked. But EJB A doesn't know anything about EJB C, it's not available in its ENC so Seam can't look it up and we have a problem for which I don't know any solution.
[Message sent by forum member 'koser' (koser)]

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