Uploaded image for project: 'Weld'
  1. Weld
  2. WELD-632

EMF Resource declaration in a static producer field of a Singleton EJB results in a null instance exception

XMLWordPrintable

    • Hide

      Beans attached.

      Show
      Beans attached.

      I have a developer test that thests the following scenario:

      • Injection of an EMF into a Servlet. This EMF is produced through a producer field in a Singleton EJB in that war.

      If the resource(JPA EMF) is declared by making a static field in a singleton EJB as a producer field [1]
      and this EMF is injected in a servlet in the war, a null instance exception when the injected reference to the EMF is used [2].

      I have attached the relevant beans with this bug report.

      [1]
      A sample bean and a test case to reproduce is at https://svn.dev.java.net/svn/glassfish-svn/trunk/v2/appserv-tests/devtests/cdi/javaee-component-resources/jpa-resource-injection-with-singleton-ejb-producer/

      Bean snippet:
      > @javax.ejb.Singleton
      > public class JPAResourceProducerSingletonEJB_StaticField

      { > @Produces @PersistenceUnit(unitName="pu1") @ProducedViaStaticField > public static EntityManagerFactory customerDatabasePersistenceUnit1; > }

      >
      > and I inject this EMF in the servlet as
      > @Inject
      > @ProducedViaStaticField
      > private EntityManagerFactory emf_static;
      >
      >
      > [2]
      > ---- server log snippet ----
      > [#|2010-08-20T15:53:52.613+0530|WARNING|glassfish3.1|javax.enterprise.system.container.web.com.sun.enterprise.web|_ThreadID=14;_ThreadName=Thread-1;|StandardWrapperValve[mytest]: PWC1406: Servlet.service() for servlet mytest threw exception
      > org.jboss.weld.exceptions.NullInstanceException: WELD-000044 Unable to obtain instance from org.jboss.weld.bean-/export/work/workspaces/gfv3/v3/distributions/glassfish/target/stage/glassfishv3/glassfish/domains/domain1/applications/cdi-jpa-resource-injection-in-singleton-ejb-web/-ProducerField-test.ejb.JPAResourceProducerSingletonEJB_StaticField.customerDatabasePersistenceUnit1
      > at org.jboss.weld.bean.builtin.CallableMethodHandler.invoke(CallableMethodHandler.java:55)
      > at org.jboss.weld.bean.proxy.EnterpriseTargetBeanInstance.invoke(EnterpriseTargetBeanInstance.java:62)
      > at org.jboss.weldx.persistence.EntityManagerFactory_$$WeldProxy.toString(EntityManagerFactory$$_WeldProxy.java)
      > at java.lang.String.valueOf(String.java:2826)
      > at java.lang.StringBuilder.append(StringBuilder.java:115)
      > at test.servlet.JPAResourceInjectionServletFromSingletonEJB.doGet(JPAResourceInjectionServletFromSingletonEJB.java:105)
      > ---- server log snippet —

              pmuiratbleepbleep Pete Muir (Inactive)
              sivakumart_jira Sivakumar Thyagarajan (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved: