11 Replies Latest reply on Jan 20, 2010 6:40 AM by Gavin King

    CDI spec "3.5.1. Declaring a resource" does not seem to work in RI?

    Johan Eltes Newbie

      I have a Junit-driven test that uses the embeddable EJB container to perform an integration test of an EJB. The Stateless EJB invokes a CDI bean (DAO) that has an..


      @Inject EntityManager em;


      Then there is another (utility) CDI bean that defines a producer field for the persistence context:


      public class Resources {
              @Produces @PersistenceContext
              EntityManager em;
      }


      With this set-up, the embeddable container (RI) reports:



      Unable to retrieve EntityManagerFactory for unitName null

      If I change the DAO to a @Stateless EJB, test fails with:


      WELD-000044 Unable to obtain instance from org.jboss.weld.bean-/...Resources.em


      If I remove the Resource class above, and define the persistence context in the dao (CDI bean), like this:


              @PersistenceContext
              protected EntityManager em;
      ...I get the following error:



      Unable to retrieve EntityManagerFactory for unitName null

      What finally makes the test run clean, is to declare the DAO as @Stateless.


      To my understanding, all the variations listed above should be valid. From my tests with the embeddable EJB container, it seems the integration of EJB 3.0 Light and CDI as described in chapter 3.5.1. Declaring a resource has yet to be implemented?