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:

      public class EntityManagerProducer {
          private EntityManager em;
          public EntityManager getEntityManager() {
              return em;
      public class A {
          private EntityManager em;
          public List<University> getUniversities() {
              return em.createNamedQuery("University.findAll").getResultList();
      <h:dataTable value="#{a.universities}" var="item">
              <h:outputText value="#{item.name}"/>


      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.