1 Reply Latest reply on Apr 8, 2010 9:14 AM by Bernard Labno

    Entity Manager config problems

    Craig Horrell Newbie

      I an getting a NullPointerException when trying to use the Entity Manager.


      Code Snippet:


      public class TestWs {
        @In
        private EntityManager entityMgr;
      
        public TestWs() {
        }
      
        @GET
        @Produces({"application/xml"})
        public Response getMessage(@QueryParam("orderId") final long orderId) {
      
          ResponseBuilder rspBuilder = null;
      
          try {
            System.out.println("\nOrder ID = " + orderId);
            if (entityMgr == null) {
              System.out.println("\nStupid em is null.\n");
            }
            ...
          }
      



      From components.xml:




        <persistence:managed-persistence-context
          name="entityMgr"
          auto-create="true"
          persistence-unit-jndi-name="java:/restEntityManagerFactory"/>
      



      From persistence.xml:




        <persistence-unit name="rest">
          <provider>org.hibernate.ejb.HibernatePersistence</provider>
          <jta-data-source>java:/RestfulDS</jta-data-source>
          <properties>
            <property name="hibernate.dialect"         value="org.hibernate.dialect.Oracle9iDialect"/>
            <property name="hibernate.show_sql"        value="true"/>
            <property name="hibernate.format_sql"      value="true"/>
            <property name="hibernate.jdbc.batch_size" value="1000"/>
            <property name="hibernate.default_schema"  value="OT_APPS"/>
            <property name="jboss.entity.manager.factory.jndi.name" value="java:/restEntityManagerFactory"/>
          </properties>
        </persistence-unit>
      



      From the log:




      2010-04-07 15:50:25,216 INFO  [STDOUT] (http-127.0.0.1-8080-1) 
      Order ID = 1234
      2010-04-07 15:50:25,216 INFO  [STDOUT] (http-127.0.0.1-8080-1) 
      Stupid em is null.
      2010-04-07 15:50:25,216 ERROR [STDERR] (http-127.0.0.1-8080-1) java.lang.NullPointerException
      2010-04-07 15:50:25,216 ERROR [STDERR] (http-127.0.0.1-8080-1)      at com.mailexpress.webservice.rest.tracking.service.TestWs.getMessage(TestWs.java:34)
      2010-04-07 15:50:25,216 ERROR [STDERR] (http-127.0.0.1-8080-1)      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      2010-04-07 15:50:25,216 ERROR [STDERR] (http-127.0.0.1-8080-1)      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      2010-04-07 15:50:25,216 ERROR [STDERR] (http-127.0.0.1-8080-1)      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      2010-04-07 15:50:25,216 ERROR [STDERR] (http-127.0.0.1-8080-1)      at java.lang.reflect.Method.invoke(Method.java:597)
      2010-04-07 15:50:25,216 ERROR [STDERR] (http-127.0.0.1-8080-1)      at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:124)
      



      Any ideas ?


      Thanks,
      Craig.