2 Replies Latest reply on Jul 7, 2006 12:46 PM by Filippo

    Injecting EntityManager with an interceptor

    Scott Balmos Newbie

      Solve one question, end up finding another. ;)

      I'm trying to get my EntityManager injected into my DAO layer, by specifying the core class of the DAO as an interceptor to my SLSB, which is acting as a SOAP service endpoint (enough buzzwords?).

      I know by the deployment logs that the interceptor is being registered correctly. But no matter what, the EntityManager never gets injected, and remains null.

      The persistence unit is configured in a separate persistence JAR from the EJB JAR, and everything is packed into an EAR. See below for the relevant annotations and snippets from everything:

      @Stateless @WebService
      public class SOAPBackend

      public class EJB3DAOFactory
      private static final Logger log = Logger.getLogger(EJB3DAOFactory.class);

      @PersistenceContext(unitName = "simunex")
      protected EntityManager em;

      public EJB3DAOFactory() {}

      protected EntityManager getEntityManager()
      if (em == null) { log.debug("EntityManager is null!"); }
      return em;

      Like I said, the deployment logs correctly register the interceptor-based dependency on the EntityManager, and defers starting of the EJB until after Hibernate starts up. But whenever I attempt to perform a SOAP operation, which is serviced by SOAPBackend, the EntityManager remains null.

      Options? I'd rather stay away from global JNDI lookup if possible. I know about the scoped deployment of the persistence unit. But I would've thought that a persistence unit defined in one JAR of an EAR would be within the scope of another JAR of the EAR.