users@glassfish.java.net

Re: Putting EntityManagerFactory into JNDI

From: <glassfish_at_javadesktop.org>
Date: Wed, 23 Jan 2008 07:19:20 PST

I'm not familiar with SEAM, but if your SEAM code is invoked from a EJB, then the SEAM code will see the same ENC environment as the EJB that it is invoked from. You can either put an annotation on the EJB and specify the "name" property of the annotation. This is the name at which the EntityManagerFactory will available in the ENC JNDI context.

So for example, if you specify the annotation as:

@PersistenceUnit(name="persistence/somename" ...)

You can then look it up with a
   InitialContext initialContext = new InitialialContext();
   EntityManagerFactory emf = (EntityManagerFactory) initialContext.lookup("java:comp/env/persistence/somename");

You can also replace the annotation with a "persistence-unit-ref" in your ejb-jar.xml

I've also done something different in some code that I'm working on. I wanted to wrap an EntityManager with my own extended implementation, so what I did is in my EJB, I created a ThreadLocal object that contained my wrapped EntityManager and then elsewhere I retrieved this ThreadLocal object.
[Message sent by forum member 'bbergquist' (bbergquist)]

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