title: EntityManager.createQuery() throws NullPointerException
body: <p>'m getting NullPointerException everytime any <code>EntityManager.createQuery()</code> or <code>EntityManager.createNamedQuery()</code> is called. </p>
  
  <p>I'm using Glassfish 4.0, Hibernate 4.3.5 and EJB.</p>
  
  <p>I have following hierarchy:</p>
  
  <p>DaoTemplate where I have PersistenceContext and generic methods</p>
  
  <pre><code>@Singleton
  public class DaoTemplate&lt;T extends IdEntityInterface&gt; {
      @PersistenceContext(unitName = "pu_name")
      protected EntityManager em;
      ....
  }
  </code></pre>
  
  <p>Abstract class with constructor beacuse bean can't extend another bean.</p>
  
  <pre><code>public abstract class AbstractDaoTemplate&lt;T extends IdEntityInterface&gt; extends    DaoTemplate&lt;T&gt; {
  
      public AbstractDaoTemplate(Class&lt;T&gt; entityClass) {
          super(entityClass);
      }
  
  }
  </code></pre>
  
  <p>And then I have Dao.</p>
  
  <pre><code>@Singleton
  public class SomeDao extends AbstractDaoTemplate&lt;SomeEntity&gt; {
  
      public SomeDao() {
          super(SomeEntity.class)
      }        
  
      @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
      public List&lt;SomeEntity&gt; someDaoMethod() {
          ...
          em.createQuery("SomeQuery");
          ...   
      }
  }
  </code></pre>
  
  <p>When someDaoMethod is invoked NullPointerException is thrown on line with <code>em.createQuery("SomeQuery")</code> but <code>em</code> is not null.</p>
  
  <p>I've also tried to call <code>em.createQuery("SomeQuery")</code> from debugger window, here is the output:</p>
  
  <pre><code>Exception occurred in target VM:  
  java.lang.NullPointerException: 
      at org.hibernate.engine.transaction.internal.jta.JtaStatusHelper.getStatus(JtaStatusHelper.java:76)
      at org.hibernate.engine.transaction.internal.jta.JtaStatusHelper.isActive(JtaStatusHelper.java:118)
      at org.hibernate.engine.transaction.internal.jta.CMTTransaction.join(CMTTransaction.java:149)
      at org.hibernate.jpa.spi.AbstractEntityManagerImpl.joinTransaction(AbstractEntityManagerImpl.java:1602)
      at org.hibernate.jpa.spi.AbstractEntityManagerImpl.postInit(AbstractEntityManagerImpl.java:210)
      at org.hibernate.jpa.internal.EntityManagerImpl.&lt;init&gt;(EntityManagerImpl.java:91)
      at org.hibernate.jpa.internal.EntityManagerFactoryImpl.internalCreateEntityManager(EntityManagerFactoryImpl.java:345)
      at org.hibernate.jpa.internal.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:338)
      at com.sun.enterprise.container.common.impl.EntityManagerWrapper._getDelegate(EntityManagerWrapper.java:197)
      at com.sun.enterprise.container.common.impl.EntityManagerWrapper.createQuery(EntityManagerWrapper.java:455)
      at eu.comcom.kweportal.dao.ShipmentDao.getActiveOldShipments(ShipmentDao.java:196)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1081)
      at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1153)
      at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:4695)
      at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:630)
      at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
      at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:582)
      at org.jboss.weld.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(Abstrac tEJBRequestScopeActivationInterceptor.java:46)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:883)
      at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
      at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:582)
      at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doCall(SystemInterceptorProxy.java:163)
      at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:140)
      at sun.reflect.GeneratedMethodAccessor77.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:883)
      at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
      at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:369)
      at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:4667)
      at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:4655)
      at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:212)
      at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLoca    lObjectInvocationHandlerDelegate.java:88)
      at com.sun.proxy.$Proxy542.getActiveOldShipments(Unknown Source)
      at eu.comcom.kweportal.dao.__EJB31_Generated__ShipmentDao__Intf____Bean__.getActiveOldShipments(Unknown Source)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at org.jboss.weld.util.reflection.Reflections.invokeAndUnwrap(Reflections.java:396)
      at org.jboss.weld.bean.proxy.EnterpriseBeanProxyMethodHandler.invoke(EnterpriseBeanProxyMethodHandler.java:108)
      at org.jboss.weld.bean.proxy.EnterpriseTargetBeanInstance.invoke(EnterpriseTargetBeanInstance.java:56)
      at org.jboss.weld.bean.proxy.InjectionPointPropagatingEnterpriseTargetBeanInstance.invoke(InjectionPointPropagatingEnterpriseTargetBeanInstance.java:63)
      at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:101)
      at eu.comcom.kweportal.dao.ShipmentDao$Proxy$_$$_Weld$EnterpriseProxy$.getActiveOldShipments(Unknown Source)
      at eu.comcom.kweportal.schedule.ActualTimeScheduler.updatePastMilestonesTimes(ActualTimeScheduler.java:41)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1081)
      at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1153)
      at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:4695)
      at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:630)
      at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
      at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:582)
      at org.jboss.weld.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke (AbstractEJBRequestScopeActivationInterceptor.java:55)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:883)
      at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
      at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:582)
      at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doCall(SystemInterceptorProxy.java:163)
      at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundTimeout(SystemInterceptorProxy.java:145)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:883)
      at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
      at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:369)
      at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:4667)
      at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:4655)
      at com.sun.ejb.containers.BaseContainer.callEJBTimeout(BaseContainer.java:3993)
      at com.sun.ejb.containers.EJBTimerService.deliverTimeout(EJBTimerService.java:1199)
      at com.sun.ejb.containers.EJBTimerService.access$000(EJBTimerService.java:89)
      at com.sun.ejb.containers.EJBTimerService$TaskExpiredWork.run(EJBTimerService.java:1919)
      at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
      at java.util.concurrent.FutureTask.run(FutureTask.java:262)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      at java.lang.Thread.run(Thread.java:744)
  </code></pre>
  
  <p>and persistence.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"&gt;
    &lt;persistence-unit name="pu_name" transaction-type="JTA"&gt;
        &lt;provider&gt;org.hibernate.jpa.HibernatePersistenceProvider&lt;/provider&gt;
        &lt;jta-data-source&gt;jdbc/kweportal&lt;/jta-data-source&gt;
        &lt;exclude-unlisted-classes&gt;false&lt;/exclude-unlisted-classes&gt;
        &lt;properties&gt;
            &lt;property name="hibernate.ejb.cfgfile" value="hibernate.cfg.xml"/&gt;
        &lt;/properties&gt;
    &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p>Any ideas what could be wrong?</p>