2 Replies Latest reply on Apr 19, 2010 10:40 AM by Donatas Ciuksys

    Injection of Extended persistence context does not work

    Donatas Ciuksys Newbie

      This scenario does not work on GlassFish v3.0.1 promoted build:


      @SessionScoped
      @Stateful
      public class EntityManagerProducer {
          @PersistenceContext(type=PersistenceContextType.EXTENDED)
          private EntityManager em;
          
          @Produces
          public EntityManager getEntityManager() {
              return em;
          }
      }
      
      @Named
      @SessionScoped
      @Stateful
      public class A {
          @Inject
          private EntityManager em;
      
          public List<University> getUniversities() {
              return em.createNamedQuery("University.findAll").getResultList();
          }    
      }
      
      <h:dataTable value="#{a.universities}" var="item">
          <h:column>
              <h:outputText value="#{item.name}"/>
          </h:column>
      </h:dataTable>
      



      Exception:


      Caused by: java.lang.NullPointerException
              at com.sun.enterprise.container.common.impl.EntityManagerWrapper.createNamedQuery(EntityManagerWrapper.java:522)
              at lt.mycompany.template.A.getUniversities(A.java:42)


      Additionally, checking em.getDelegate() reveals it is null.


      If I change PersistenceContext type to TRANSACTIONAL, the case starts working.
      Also, if some operations on entity manager are done before injecting it to A, everything starts to work too.


      It seems like EntityManager delegate is not initialized if it is of type EXTENDED.