title: PersistenceContext EntityManager injection NullPointerException
body: <p>I have a war containing the following:</p>
  
  <pre><code>META-INF/MANIFEST.MF
  WEB-INF/classes/META-INF/persistence.xml
  WEB-INF/classes/com/test/service/TestServlet.class
  WEB-INF/classes/com/test/service/TestEntity.class
  WEB-INF/classes/jndi.properties
  WEB-INF/classes/postgresql-ds.xml
  WEB-INF/jboss-web.xml
  WEB-INF/web.xml
  index.jsp</code></pre>
  
  <p>persistence.xml:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;persistence 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_1_0.xsd" version="1.0"&gt;
      &lt;persistence-unit name="test"&gt;
          &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
          &lt;jta-data-source&gt;java:/TestDS&lt;/jta-data-source&gt;
  
          &lt;properties&gt;
              &lt;property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/&gt;
              &lt;property name="hibernate.hbm2ddl.auto" value="update" /&gt;
              &lt;property name="hibernate.show_sql" value="true" /&gt;
          &lt;/properties&gt;
      &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p>web.xml:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;!DOCTYPE web-app PUBLIC
   "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
   "http://java.sun.com/dtd/web-app_2_3.dtd" &gt;
  
  &lt;web-app&gt;
    &lt;display-name&gt;Test Web Application&lt;/display-name&gt;
  
      &lt;context-param&gt;
          &lt;param-name&gt;resteasy.scan&lt;/param-name&gt;
          &lt;param-value&gt;true&lt;/param-value&gt;
      &lt;/context-param&gt;
      &lt;listener&gt;
          &lt;listener-class&gt;org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap&lt;/listener-class&gt;
      &lt;/listener&gt;
      &lt;servlet&gt;
          &lt;servlet-name&gt;Resteasy&lt;/servlet-name&gt;
          &lt;servlet-class&gt;org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher&lt;/servlet-class&gt;
      &lt;/servlet&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;Resteasy&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/service/*&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  
      &lt;resource-ref&gt;
          &lt;res-ref-name&gt;TestDS&lt;/res-ref-name&gt;
          &lt;res-type&gt;javax.sql.DataSource&lt;/res-type&gt;
          &lt;res-auth&gt;Container&lt;/res-auth&gt;
          &lt;res-sharing-scope&gt;Shareable&lt;/res-sharing-scope&gt;
      &lt;/resource-ref&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>My TestServlet class is as follows:</p>
  
  <pre><code>package com.test.service;
  
  import java.util.*;
  import javax.persistence.*;
  import javax.ws.rs.*;
  
  @Path("/service")
  public class TestService {
  
      @PersistenceContext(unitName = "test")
      private EntityManager em;
  
      @GET
      @Path("/get")
      @Produces("application/json")
      public List get() {
          return em.createQuery("from TestEntity").getResultList();
      }
  }</code></pre>
  
  <p>When the get() method is invoked I get a NullPointerException; the EntityManager hasn't been injected. Any suggestions on what I might be missing or how I can diagnose it? There's very little in the server log.</p>
  
  <p>I'm sure I had this working without the jboss-web.xml or the datasource entry in web.xml. I've deployed the ds.xml to the deploy directory separately too and that's definitely picked up - I can see it in the JMX console.</p>
  
  <p>Tried using JBoss 4.2.3 and a 6.0 build with the same result.</p>