users@glassfish.java.net

EntityManager not being injected into abstract EJB?

From: <glassfish_at_javadesktop.org>
Date: Wed, 14 Apr 2010 09:54:22 PDT

I'm using Glassfish 3.0.1 in embedded mode.

I (like millions of others) have an AbstractDAO class. It contains a @PersistenceContext annotation that is applied to an internal protected EntityManager em field.

At test time, I have a ConcreteDAO that exends AbstractDAO and makes use of the injected em.

However, the test fails when em.persist() is called, claiming that injection into AbstractDAO's em has failed. So the em is non-null, but the lazy initialization of its innards fails.

I was wondering if there are known problems in this area. The error message, at root, is the following, and bears a suspicious resemblance to issue 7473 (fixed; see https://glassfish.dev.java.net/issues/show_bug.cgi?id=7473):

[code]
Caused by: java.lang.IllegalStateException: Unable to retrieve EntityManagerFactory for unitName null
        at com.sun.enterprise.container.common.impl.EntityManagerWrapper.init(EntityManagerWrapper.java:121)
        at com.sun.enterprise.container.common.impl.EntityManagerWrapper.doTxRequiredCheck(EntityManagerWrapper.java:141)
        at com.sun.enterprise.container.common.impl.EntityManagerWrapper.doTransactionScopedTxCheck(EntityManagerWrapper.java:134)
        at com.sun.enterprise.container.common.impl.EntityManagerWrapper.persist(EntityManagerWrapper.java:252)
        at com.jenzabar.ngp.dao.ejb.AbstractDAO.persist(AbstractDAO.java:44)
[/code]

If it matters, at test time AbstractDAO is found in its own jar file (no ejb-jar.xml) and ConcreteDAO is found on the classpath by the Glassfish embedded scanning mode triggered by EJBContainer.createEJBContainer(). Perhaps there's an issue there?

Best,
Laird
[Message sent by forum member 'ljnelson']

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