6 Replies Latest reply on Mar 18, 2014 12:27 PM by dhileman

    Java, EntityManager always null when using JTA datasource

    dhileman

      Hello all.  New member here, and new to JBoss/Wildfly.  I have been stuck on a problem for a few days now.  I am trying to setup a simple REST web service to use JPA to manipulate a MySQL database.  I am using Wildfly 8.0 Final with Hibernate 4.3. Here is how my Eclipse project is setup:

       

      PersonApp.ear (Enterprise project)
      |
      |---PersonData.jar (JPA project)
      |   |
      |   |---Person (Entity)
      |   |---PersonManager
      |   |---persistence.xml (in META-INF)
      |
      |---PersonRest.war (Web project)
          |
          |---PersonService
      
      
      
      

       

      PersonService (in PersonRest project) contains one @GET method which calls PersonManager.

      PersonManager is a wrapper for EntityManager.  This is where my application is failing.  I can't get a handle on EntityManager.

       

      PersonService:

      @Path("/PersonService")
      public class PersonService {
      
           @GET
           @Produces("text/plain")
           public String getAllPersons() {
      
                PersonManager manager = new PersonManager();
                List<Person> list = manager.findAll(); //fails with null pointer
           }
      }
      
      
      
      

       

      PersonManager:

      public class PersonManager {
      
           public List<Person> findAll() {
      
                EntityManagerFactory emf = Persistence.createEntityManagerFactory("PersonData"); //returns null
                EntityManager em = emf.createEntityManager(); //null pointer exception on this line. emf is null
                List<Person> list = em.createQuery("SELECT p FROM Person p").getResultList();
                return list;
           }
      }
      
      
      
      

       

      persistence.xml:

      <?xml version="1.0" encoding="UTF-8"?>
      <persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
          <persistence-unit name="PersonData" transaction-type="JTA">
              <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
              <jta-data-source>java:jboss/datasources/MySqlDS</jta-data-source>
              <class>com.csc.data.Person</class>
              <properties>
                  <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
                  <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
              </properties>
          </persistence-unit>
      </persistence>
      
      
      
      

       

      Here is the Wildfly startup output:

      14:31:14,607 INFO  [org.jboss.modules] (main) JBoss Modules version 1.3.0.Final
      14:31:14,841 INFO  [org.jboss.msc] (main) JBoss MSC version 1.2.0.Final
      14:31:14,919 INFO  [org.jboss.as] (MSC service thread 1-6) JBAS015899: WildFly 8.0.0.Final "WildFly" starting
      14:31:15,871 INFO  [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) JBAS015003: Found PersonApp.ear in deployment directory. To trigger deployment create a file called PersonApp.ear.dodeploy
      14:31:15,887 INFO  [org.jboss.as.server] (Controller Boot Thread) JBAS015888: Creating http management service using socket-binding (management-http)
      14:31:15,903 INFO  [org.xnio] (MSC service thread 1-8) XNIO version 3.2.0.Final
      14:31:15,919 INFO  [org.xnio.nio] (MSC service thread 1-8) XNIO NIO Implementation Version 3.2.0.Final
      14:31:15,934 INFO  [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 33) JBAS010280: Activating Infinispan subsystem.
      14:31:15,950 INFO  [org.jboss.as.security] (ServerService Thread Pool -- 46) JBAS013171: Activating Security Subsystem
      14:31:15,966 INFO  [org.jboss.as.webservices] (ServerService Thread Pool -- 50) JBAS015537: Activating WebServices Extension
      14:31:15,997 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-6) JBAS017502: Undertow 1.0.0.Final starting
      14:31:15,997 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 49) JBAS017502: Undertow 1.0.0.Final starting
      14:31:15,997 INFO  [org.jboss.as.security] (MSC service thread 1-2) JBAS013170: Current PicketBox version=4.0.20.Final
      14:31:15,997 INFO  [org.jboss.as.naming] (ServerService Thread Pool -- 41) JBAS011800: Activating Naming Subsystem
      14:31:15,997 INFO  [org.jboss.as.jsf] (ServerService Thread Pool -- 39) JBAS012615: Activated the following JSF Implementations: [main]
      14:31:16,028 INFO  [org.jboss.as.connector.logging] (MSC service thread 1-5) JBAS010408: Starting JCA Subsystem (IronJacamar 1.1.3.Final)
      14:31:16,075 INFO  [org.jboss.as.naming] (MSC service thread 1-5) JBAS011802: Starting Naming Service
      14:31:16,075 INFO  [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 28) JBAS010403: Deploying JDBC-compliant driver class org.h2.Driver (version 1.3)
      14:31:16,090 INFO  [org.jboss.as.mail.extension] (MSC service thread 1-6) JBAS015400: Bound mail session [java:jboss/mail/Default]
      14:31:16,106 INFO  [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 28) JBAS010404: Deploying non-JDBC-compliant driver class com.mysql.jdbc.Driver (version 5.1)
      14:31:16,106 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-4) JBAS010417: Started Driver service with driver-name = h2
      14:31:16,106 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-4) JBAS010417: Started Driver service with driver-name = com.mysql
      14:31:16,184 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 49) JBAS017527: Creating file handler for path C:\wildfly-8.0.0.Final/welcome-content
      14:31:16,200 INFO  [org.jboss.remoting] (MSC service thread 1-1) JBoss Remoting version 4.0.0.Final
      14:31:16,434 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-2) JBAS017525: Started server default-server.
      14:31:16,543 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-2) JBAS017531: Host default-host starting
      14:31:16,605 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-6) JBAS017519: Undertow HTTP listener default listening on localhost/127.0.0.1:8080
      14:31:16,652 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-4) JBAS010400: Bound data source [java:jboss/datasources/MySqlDS]
      14:31:16,730 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-4) JBAS015876: Starting deployment of "PersonApp.ear" (runtime-name: "PersonApp.ear")
      14:31:16,746 INFO  [org.jboss.as.server.deployment.scanner] (MSC service thread 1-7) JBAS015012: Started FileSystemDeploymentService for directory C:\wildfly-8.0.0.Final\standalone\deployments
      14:31:16,761 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-7) JBAS010400: Bound data source [java:jboss/datasources/ExampleDS]
      14:31:16,824 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-3) JBAS015876: Starting deployment of "null" (runtime-name: "PersonRest.war")
      14:31:16,855 INFO  [org.jboss.ws.common.management] (MSC service thread 1-6) JBWS022052: Starting JBoss Web Services - Stack CXF Server 4.2.3.Final
      14:31:16,870 INFO  [org.jboss.as.jpa] (MSC service thread 1-3) JBAS011401: Read persistence.xml for PersonData
      14:31:16,933 INFO  [org.jboss.as.jpa] (ServerService Thread Pool -- 52) JBAS011409: Starting Persistence Unit (phase 1 of 2) Service 'PersonApp.ear#PersonData'
      14:31:16,948 INFO  [org.hibernate.jpa.internal.util.LogHelper] (ServerService Thread Pool -- 52) HHH000204: Processing PersistenceUnitInfo [
          name: PersonData
          ...]
      14:31:16,996 INFO  [org.hibernate.Version] (ServerService Thread Pool -- 52) HHH000412: Hibernate Core {4.3.1.Final}
      14:31:17,012 INFO  [org.hibernate.cfg.Environment] (ServerService Thread Pool -- 52) HHH000206: hibernate.properties not found
      14:31:17,012 INFO  [org.hibernate.cfg.Environment] (ServerService Thread Pool -- 52) HHH000021: Bytecode provider name : javassist
      14:31:17,152 INFO  [org.jboss.as.jpa] (ServerService Thread Pool -- 52) JBAS011409: Starting Persistence Unit (phase 2 of 2) Service 'PersonApp.ear#PersonData'
      14:31:17,277 INFO  [org.hibernate.annotations.common.Version] (ServerService Thread Pool -- 52) HCANN000001: Hibernate Commons Annotations {4.0.4.Final}
      14:31:17,511 INFO  [org.hibernate.dialect.Dialect] (ServerService Thread Pool -- 52) HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
      14:31:17,589 INFO  [org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory] (ServerService Thread Pool -- 52) HHH000397: Using ASTQueryTranslatorFactory
      14:31:17,620 INFO  [org.hibernate.validator.internal.util.Version] (ServerService Thread Pool -- 52) HV000001: Hibernate Validator 5.0.3.Final
      14:31:17,885 INFO  [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 52) HHH000227: Running hbm2ddl schema export
      14:31:17,932 INFO  [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 52) HHH000230: Schema export complete
      14:31:18,197 INFO  [org.jboss.resteasy.spi.ResteasyDeployment] (MSC service thread 1-2) Deploying javax.ws.rs.core.Application: class com.csc.rest.service.PersonRest
      14:31:18,197 INFO  [org.jboss.resteasy.spi.ResteasyDeployment] (MSC service thread 1-2) Adding singleton resource com.csc.rest.service.PersonService from Application class com.csc.rest.service.PersonRest
      14:31:18,323 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-2) JBAS017534: Registered web context: /PersonRest
      14:31:18,370 INFO  [org.jboss.as.server] (ServerService Thread Pool -- 29) JBAS018559: Deployed "PersonApp.ear" (runtime-name : "PersonApp.ear")
      14:31:18,417 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015961: Http management interface listening on http://127.0.0.1:9990/management
      14:31:18,417 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015951: Admin console listening on http://127.0.0.1:9990
      14:31:18,417 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015874: WildFly 8.0.0.Final "WildFly" started in 4059ms - Started 291 of 351 services (98 services are lazy, passive or on-demand)
      
      
      
      

       

      Here is the error when I access the service through the web browser:

      14:32:06,221 INFO  [org.hibernate.jpa.internal.util.LogHelper] (default task-2) HHH000204: Processing PersistenceUnitInfo [
          name: PersonData
          ...]
      14:32:06,236 INFO  [org.hibernate.dialect.Dialect] (default task-2) HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
      14:32:06,236 INFO  [org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory] (default task-2) HHH000397: Using ASTQueryTranslatorFactory
      14:32:06,252 INFO  [org.hibernate.tool.hbm2ddl.SchemaExport] (default task-2) HHH000227: Running hbm2ddl schema export
      14:32:06,268 INFO  [org.hibernate.tool.hbm2ddl.SchemaExport] (default task-2) HHH000230: Schema export complete
      14:32:06,300 ERROR [io.undertow.request] (default task-2) UT005023: Exception handling request to /PersonRest/PersonService: org.jboss.resteasy.spi.UnhandledException: java.lang.NullPointerException
          at org.jboss.resteasy.core.ExceptionHandler.handleApplicationException(ExceptionHandler.java:76) [resteasy-jaxrs-3.0.6.Final.jar:]
          at org.jboss.resteasy.core.ExceptionHandler.handleException(ExceptionHandler.java:212) [resteasy-jaxrs-3.0.6.Final.jar:]
          at org.jboss.resteasy.core.SynchronousDispatcher.writeException(SynchronousDispatcher.java:149) [resteasy-jaxrs-3.0.6.Final.jar:]
          at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:372) [resteasy-jaxrs-3.0.6.Final.jar:]
          at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:179) [resteasy-jaxrs-3.0.6.Final.jar:]
          at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220) [resteasy-jaxrs-3.0.6.Final.jar:]
          at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56) [resteasy-jaxrs-3.0.6.Final.jar:]
          at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51) [resteasy-jaxrs-3.0.6.Final.jar:]
          at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) [jboss-servlet-api_3.1_spec-1.0.0.Final.jar:1.0.0.Final]
          at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
          at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
          at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
          at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
          at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.0.Final.jar:1.0.0.Final]
          at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:113) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
          at io.undertow.security.handlers.AuthenticationCallHandler.handleRequest(AuthenticationCallHandler.java:52) [undertow-core-1.0.0.Final.jar:1.0.0.Final]
          at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:45) [undertow-core-1.0.0.Final.jar:1.0.0.Final]
          at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:61) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
          at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
          at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76) [undertow-core-1.0.0.Final.jar:1.0.0.Final]
          at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.0.Final.jar:1.0.0.Final]
          at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
          at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.0.Final.jar:1.0.0.Final]
          at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.0.Final.jar:1.0.0.Final]
          at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:240) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
          at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:227) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
          at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:73) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
          at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:146) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
          at io.undertow.server.Connectors.executeRootHandler(Connectors.java:168) [undertow-core-1.0.0.Final.jar:1.0.0.Final]
          at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:687) [undertow-core-1.0.0.Final.jar:1.0.0.Final]
          at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [rt.jar:1.7.0_51]
          at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [rt.jar:1.7.0_51]
          at java.lang.Thread.run(Unknown Source) [rt.jar:1.7.0_51]
      Caused by: java.lang.NullPointerException
          at org.hibernate.engine.transaction.internal.jta.JtaStatusHelper.getStatus(JtaStatusHelper.java:76) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
          at org.hibernate.engine.transaction.internal.jta.JtaStatusHelper.isActive(JtaStatusHelper.java:118) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
          at org.hibernate.engine.transaction.internal.jta.CMTTransaction.join(CMTTransaction.java:149) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
          at org.hibernate.jpa.spi.AbstractEntityManagerImpl.joinTransaction(AbstractEntityManagerImpl.java:1602) [hibernate-entitymanager-4.3.1.Final.jar:4.3.1.Final]
          at org.hibernate.jpa.spi.AbstractEntityManagerImpl.postInit(AbstractEntityManagerImpl.java:210) [hibernate-entitymanager-4.3.1.Final.jar:4.3.1.Final]
          at org.hibernate.jpa.internal.EntityManagerImpl.<init>(EntityManagerImpl.java:91) [hibernate-entitymanager-4.3.1.Final.jar:4.3.1.Final]
          at org.hibernate.jpa.internal.EntityManagerFactoryImpl.internalCreateEntityManager(EntityManagerFactoryImpl.java:345) [hibernate-entitymanager-4.3.1.Final.jar:4.3.1.Final]
          at org.hibernate.jpa.internal.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:313) [hibernate-entitymanager-4.3.1.Final.jar:4.3.1.Final]
          at com.csc.data.PersonManager.findAll(PersonManager.java:51) [PersonData.jar:]
          at com.csc.rest.service.PersonService.getAllPersons(PersonService.java:21) [classes:]
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_51]
          at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) [rt.jar:1.7.0_51]
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) [rt.jar:1.7.0_51]
          at java.lang.reflect.Method.invoke(Unknown Source) [rt.jar:1.7.0_51]
          at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:137) [resteasy-jaxrs-3.0.6.Final.jar:]
          at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:280) [resteasy-jaxrs-3.0.6.Final.jar:]
          at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:234) [resteasy-jaxrs-3.0.6.Final.jar:]
          at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:221) [resteasy-jaxrs-3.0.6.Final.jar:]
          at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:356) [resteasy-jaxrs-3.0.6.Final.jar:]
          ... 29 more
      
      
      
      

       

      Any idea what I am missing? One odd thing is that if I change this from a JTA jboss datasource to a local resource and specify my DB connection in persistence.xml, everything works fine. In Wildfly admin, "Test Connection" on my datasource works properly, returning "Successfully connected to database MySqlDS", so I am assuming the datasource is configured properly.  Also, another possible clue: all data in table Person is being dropped on Wildfly startup.  I assume this is another clue that the datasource is configured properly and this is expected using <property name="hibernate.hbm2ddl.auto" value="create-drop"/>. So if there is no datasource problem, and it works with resource-local but not with JTA, what could I be missing?

       

      Thanks, Dave

       

      EDIT:

       

      I have come across the following documentation, which makes me think my current way of getting entity manager is incorrect for JTA:

      --------------------------------------------------------------------------

      With <persistence-unit transaction-type="JTA"> the container will do EntityManager (PersistenceContext/Cache) creating and tracking...

      • You cannot use the EntityManagerFactory to get an EntityManager
      • You can only get an EntityManager supplied by the container
      • An EntityManager can be injected via the @PersistenceContext annotation only (not @PersistenceUnit)

      --------------------------------------------------------------------------

      After reading this, I have tried changing how PersonManager retrieves EntityManager

      @Stateless
      public class PersonManager {  
           @PersistenceContext(unitName="PersonData")
           EntityManager em;
      
           public List<Person> findAll() {  
      
                //EntityManagerFactory emf = Persistence.createEntityManagerFactory("PersonData"); //returns null  
                //EntityManager em = emf.createEntityManager(); //null pointer exception on this line. emf is null  
                List<Person> list = em.createQuery("SELECT p FROM Person p").getResultList();  
                return list;  
           }  
      } 
      

       

      This change did not seem to resolve anything.  EntityManager is always null in this case.

        • 1. Re: Java, EntityManager always null when using JTA datasource
          hwellmann.de

          Persistence.createEntityManagerFactory() is for unmanaged environments (Java SE), not for managed environments (Java EE).

           

          @PersistenceContext(unitName="PersonData"

          EntityManager em;

           

          is the way to go.

           

          The reason your em does not get injected is that your PersonManager is not a managed bean.

           

          Change PersonService to

           

          public class PersonService {
              @Inject
              private PersonManager manager;
                @GET
              @Produces("text/plain")
              public String getAllPersons() { 
                  List<Person> list = manager.findAll();
              }
          }
          • 2. Re: Java, EntityManager always null when using JTA datasource
            dhileman

            Thank you very much for pointing me down the correct path. Unfortunately I still can't get this working due do problems with dependency inject. When I inject the PersonManager as you have shown in your example, it is not getting instantiated (null).

             

            Any idea why injection might not work in my REST service?  I have added the beans.xml to jar META-INF and war WEB-INF and also added @RequestScoped to the service.

             

            @Path("/PersonService")
            @RequestScoped
            public class PersonService {
            
                 @Inject
                 private PersonManager manager;
            
                 @GET
                 @Produces("text/plain")
                 public String getAllPersons() {
            
                      List<Person> personList = manager.findAll();    //NullPointerException - manager is null
                 }
            }
            
            
            • 3. Re: Java, EntityManager always null when using JTA datasource
              hwellmann.de

              Dependency injection differs somewhat between CDI 1.1 (Java EE 7, WildFly 8) and CDI 1.0, so this might be caused by your beans.xml. If you delete beans.xml and make sure you have a CDI scope annotation on PersonService, then things should work (assuming PersonManager is still @Stateless). Make sure to use the correct import, some of the annotations exist in multiple packages.

               

              You want

              javax.inject.Inject

              javax.enterprise.context.RequestScoped

              1 of 1 people found this helpful
              • 4. Re: Java, EntityManager always null when using JTA datasource
                dhileman

                Thanks for your response.  I have deleted beans.xml, but now the project won't deploy.  Any ideas for this issue?

                 

                org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type PersonManager with qualifiers @Default

                  at injection point [BackedAnnotatedField] @Inject private com.csc.rest.service.PersonService.manager

                  at com.csc.rest.service.PersonService.manager(PersonService.java:0)

                 

                Full Wildfly startup output:

                08:12:38,089 INFO  [org.jboss.modules] (main) JBoss Modules version 1.3.0.Final

                08:12:38,323 INFO  [org.jboss.msc] (main) JBoss MSC version 1.2.0.Final

                08:12:38,386 INFO  [org.jboss.as] (MSC service thread 1-6) JBAS015899: WildFly 8.0.0.Final "WildFly" starting

                08:12:39,322 INFO  [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) JBAS015003: Found PersonApp.ear in deployment directory. To trigger deployment create a file called PersonApp.ear.dodeploy

                08:12:39,337 INFO  [org.jboss.as.server] (Controller Boot Thread) JBAS015888: Creating http management service using socket-binding (management-http)

                08:12:39,354 INFO  [org.xnio] (MSC service thread 1-3) XNIO version 3.2.0.Final

                08:12:39,370 INFO  [org.xnio.nio] (MSC service thread 1-3) XNIO NIO Implementation Version 3.2.0.Final

                08:12:39,385 INFO  [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 33) JBAS010280: Activating Infinispan subsystem.

                08:12:39,416 INFO  [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 28) JBAS010403: Deploying JDBC-compliant driver class org.h2.Driver (version 1.3)

                08:12:39,416 INFO  [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 28) JBAS010404: Deploying non-JDBC-compliant driver class com.mysql.jdbc.Driver (version 5.1)

                08:12:39,448 INFO  [org.jboss.as.security] (ServerService Thread Pool -- 46) JBAS013171: Activating Security Subsystem

                08:12:39,448 INFO  [org.jboss.as.webservices] (ServerService Thread Pool -- 50) JBAS015537: Activating WebServices Extension

                08:12:39,463 INFO  [org.jboss.as.naming] (ServerService Thread Pool -- 41) JBAS011800: Activating Naming Subsystem

                08:12:39,479 INFO  [org.jboss.as.security] (MSC service thread 1-2) JBAS013170: Current PicketBox version=4.0.20.Final

                08:12:39,479 INFO  [org.jboss.as.jsf] (ServerService Thread Pool -- 39) JBAS012615: Activated the following JSF Implementations: [main]

                08:12:39,510 INFO  [org.jboss.remoting] (MSC service thread 1-3) JBoss Remoting version 4.0.0.Final

                08:12:39,526 INFO  [org.jboss.as.connector.logging] (MSC service thread 1-6) JBAS010408: Starting JCA Subsystem (IronJacamar 1.1.3.Final)

                08:12:39,526 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 49) JBAS017502: Undertow 1.0.0.Final starting

                08:12:39,526 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-7) JBAS017502: Undertow 1.0.0.Final starting

                08:12:39,541 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-2) JBAS010417: Started Driver service with driver-name = com.mysql

                08:12:39,541 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-2) JBAS010417: Started Driver service with driver-name = h2

                08:12:39,541 INFO  [org.jboss.as.naming] (MSC service thread 1-2) JBAS011802: Starting Naming Service

                08:12:39,541 INFO  [org.jboss.as.mail.extension] (MSC service thread 1-2) JBAS015400: Bound mail session [java:jboss/mail/Default]

                08:12:39,588 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 49) JBAS017527: Creating file handler for path C:\wildfly-8.0.0.Final/welcome-content

                08:12:39,884 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-7) JBAS017525: Started server default-server.

                08:12:39,884 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-7) JBAS017531: Host default-host starting

                08:12:40,040 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-1) JBAS017519: Undertow HTTP listener default listening on localhost/127.0.0.1:8080

                08:12:40,134 INFO  [org.jboss.as.server.deployment.scanner] (MSC service thread 1-6) JBAS015012: Started FileSystemDeploymentService for directory C:\wildfly-8.0.0.Final\standalone\deployments

                08:12:40,134 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-2) JBAS015876: Starting deployment of "PersonApp.ear" (runtime-name: "PersonApp.ear")

                08:12:40,212 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-2) JBAS015876: Starting deployment of "null" (runtime-name: "PersonRest.war")

                08:12:40,228 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-4) JBAS010400: Bound data source [java:jboss/datasources/ExampleDS]

                08:12:40,228 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-4) JBAS010400: Bound data source [java:jboss/datasources/MySqlDS]

                08:12:40,259 INFO  [org.jboss.as.jpa] (MSC service thread 1-2) JBAS011401: Read persistence.xml for PersonData

                08:12:40,321 INFO  [org.jboss.ws.common.management] (MSC service thread 1-1) JBWS022052: Starting JBoss Web Services - Stack CXF Server 4.2.3.Final

                08:12:40,337 INFO  [org.jboss.as.jpa] (ServerService Thread Pool -- 52) JBAS011409: Starting Persistence Unit (phase 1 of 2) Service 'PersonApp.ear#PersonData'

                08:12:40,352 INFO  [org.hibernate.jpa.internal.util.LogHelper] (ServerService Thread Pool -- 52) HHH000204: Processing PersistenceUnitInfo [

                    name: PersonData

                    ...]

                08:12:40,416 INFO  [org.hibernate.Version] (ServerService Thread Pool -- 52) HHH000412: Hibernate Core {4.3.1.Final}

                08:12:40,416 INFO  [org.hibernate.cfg.Environment] (ServerService Thread Pool -- 52) HHH000206: hibernate.properties not found

                08:12:40,416 INFO  [org.hibernate.cfg.Environment] (ServerService Thread Pool -- 52) HHH000021: Bytecode provider name : javassist

                08:12:40,478 INFO  [org.jboss.weld.deployer] (MSC service thread 1-8) JBAS016002: Processing weld deployment PersonApp.ear

                08:12:40,556 INFO  [org.hibernate.validator.internal.util.Version] (MSC service thread 1-8) HV000001: Hibernate Validator 5.0.3.Final

                08:12:40,665 INFO  [org.jboss.weld.deployer] (MSC service thread 1-1) JBAS016002: Processing weld deployment PersonRest.war

                08:12:40,712 INFO  [org.jboss.weld.deployer] (MSC service thread 1-6) JBAS016005: Starting Services for CDI deployment: PersonApp.ear

                08:12:40,728 INFO  [org.jboss.weld.Version] (MSC service thread 1-6) WELD-000900: 2.1.2 (Final)

                08:12:40,743 INFO  [org.jboss.weld.deployer] (MSC service thread 1-8) JBAS016008: Starting weld service for deployment PersonApp.ear

                08:12:40,868 INFO  [org.jboss.as.jpa] (ServerService Thread Pool -- 52) JBAS011409: Starting Persistence Unit (phase 2 of 2) Service 'PersonApp.ear#PersonData'

                08:12:40,931 INFO  [org.hibernate.annotations.common.Version] (ServerService Thread Pool -- 52) HCANN000001: Hibernate Commons Annotations {4.0.4.Final}

                08:12:41,180 INFO  [org.hibernate.dialect.Dialect] (ServerService Thread Pool -- 52) HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect

                08:12:41,258 INFO  [org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory] (ServerService Thread Pool -- 52) HHH000397: Using ASTQueryTranslatorFactory

                08:12:41,508 INFO  [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 52) HHH000227: Running hbm2ddl schema export

                08:12:41,556 INFO  [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 52) HHH000230: Schema export complete

                08:12:42,055 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-7) MSC000001: Failed to start service jboss.deployment.unit."PersonApp.ear".WeldStartService: org.jboss.msc.service.StartException in service jboss.deployment.unit."PersonApp.ear".WeldStartService: Failed to start service

                    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1904) [jboss-msc-1.2.0.Final.jar:1.2.0.Final]

                    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [rt.jar:1.7.0_51]

                    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [rt.jar:1.7.0_51]

                    at java.lang.Thread.run(Unknown Source) [rt.jar:1.7.0_51]

                Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type PersonManager with qualifiers @Default

                  at injection point [BackedAnnotatedField] @Inject private com.csc.rest.service.PersonService.manager

                  at com.csc.rest.service.PersonService.manager(PersonService.java:0)

                 

                    at org.jboss.weld.bootstrap.Validator.validateInjectionPointForDeploymentProblems(Validator.java:368)

                    at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:289)

                    at org.jboss.weld.bootstrap.Validator.validateGeneralBean(Validator.java:135)

                    at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:166)

                    at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:514)

                    at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:68)

                    at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:66)

                    at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:60)

                    at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:53)

                    at java.util.concurrent.FutureTask.run(Unknown Source) [rt.jar:1.7.0_51]

                    ... 3 more

                 

                08:12:42,070 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) JBAS014613: Operation ("deploy") failed - address: ([("deployment" => "PersonApp.ear")]) - failure description: {"JBAS014671: Failed services" => {"jboss.deployment.unit.\"PersonApp.ear\".WeldStartService" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"PersonApp.ear\".WeldStartService: Failed to start service

                    Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type PersonManager with qualifiers @Default

                  at injection point [BackedAnnotatedField] @Inject private com.csc.rest.service.PersonService.manager

                  at com.csc.rest.service.PersonService.manager(PersonService.java:0)

                "}}

                08:12:42,102 INFO  [org.jboss.as.server] (ServerService Thread Pool -- 29) JBAS018559: Deployed "PersonApp.ear" (runtime-name : "PersonApp.ear")

                08:12:42,102 INFO  [org.jboss.as.controller] (Controller Boot Thread) JBAS014774: Service status report

                JBAS014777:   Services which failed to start:      service jboss.deployment.unit."PersonApp.ear".WeldStartService: org.jboss.msc.service.StartException in service jboss.deployment.unit."PersonApp.ear".WeldStartService: Failed to start service

                 

                08:12:42,117 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015961: Http management interface listening on http://127.0.0.1:9990/management

                08:12:42,117 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015951: Admin console listening on http://127.0.0.1:9990

                08:12:42,117 ERROR [org.jboss.as] (Controller Boot Thread) JBAS015875: WildFly 8.0.0.Final "WildFly" started (with errors) in 4277ms - Started 295 of 378 services (23 services failed or missing dependencies, 98 services are lazy, passive or on-demand)

                08:12:42,351 INFO  [org.jboss.as.jpa] (ServerService Thread Pool -- 22) JBAS011410: Stopping Persistence Unit (phase 2 of 2) Service 'PersonApp.ear#PersonData'

                08:12:42,351 INFO  [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 22) HHH000227: Running hbm2ddl schema export

                08:12:42,351 INFO  [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 22) HHH000230: Schema export complete

                08:12:42,351 INFO  [org.jboss.weld.deployer] (MSC service thread 1-5) JBAS016009: Stopping weld service for deployment PersonApp.ear

                08:12:42,382 INFO  [org.jboss.as.jpa] (ServerService Thread Pool -- 22) JBAS011410: Stopping Persistence Unit (phase 1 of 2) Service 'PersonApp.ear#PersonData'

                08:12:42,382 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-4) JBAS015877: Stopped deployment null (runtime-name: PersonRest.war) in 38ms

                08:12:42,382 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-7) JBAS015877: Stopped deployment PersonApp.ear (runtime-name: PersonApp.ear) in 41ms

                08:12:42,414 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018558: Undeployed "PersonApp.ear" (runtime-name: "PersonApp.ear")

                08:12:42,414 INFO  [org.jboss.as.controller] (DeploymentScanner-threads - 2) JBAS014774: Service status report

                JBAS014775:    New missing/unsatisfied dependencies:

                      service jboss.deployment.subunit."PersonApp.ear"."PersonRest.war".component."com.sun.faces.config.ConfigureListener".CREATE (missing) dependents: [service jboss.deployment.subunit."PersonApp.ear"."PersonRest.war".component."com.sun.faces.config.ConfigureListener".START]

                      service jboss.deployment.subunit."PersonApp.ear"."PersonRest.war".component."com.sun.faces.config.ConfigureListener".START (missing) dependents: [service jboss.undertow.deployment.default-server.default-host./PersonRest.UndertowDeploymentInfoService, service jboss.undertow.deployment.default-server.default-host./PersonRest, service jboss.deployment.subunit."PersonApp.ear"."PersonRest.war".deploymentCompleteService]

                      service jboss.deployment.subunit."PersonApp.ear"."PersonRest.war".component."com.sun.faces.config.ConfigureListener".WeldInstantiator (missing) dependents: [service jboss.deployment.subunit."PersonApp.ear"."PersonRest.war".component."com.sun.faces.config.ConfigureListener".START]

                      service jboss.deployment.subunit."PersonApp.ear"."PersonRest.war".component."javax.faces.webapp.FacetTag".CREATE (missing) dependents: [service jboss.deployment.subunit."PersonApp.ear"."PersonRest.war".component."javax.faces.webapp.FacetTag".START]

                      service jboss.deployment.subunit."PersonApp.ear"."PersonRest.war".component."javax.faces.webapp.FacetTag".START (missing) dependents: [service jboss.undertow.deployment.default-server.default-host./PersonRest.UndertowDeploymentInfoService, service jboss.undertow.deployment.default-server.default-host./PersonRest, service jboss.deployment.subunit."PersonApp.ear"."PersonRest.war".deploymentCompleteService]

                      service jboss.deployment.subunit."PersonApp.ear"."PersonRest.war".component."javax.faces.webapp.FacetTag".WeldInstantiator (missing) dependents: [service jboss.deployment.subunit."PersonApp.ear"."PersonRest.war".component."javax.faces.webapp.FacetTag".START]

                      service jboss.deployment.subunit."PersonApp.ear"."PersonRest.war".component."javax.servlet.jsp.jstl.tlv.PermittedTaglibsTLV".CREATE (missing) dependents: [service jboss.deployment.subunit."PersonApp.ear"."PersonRest.war".component."javax.servlet.jsp.jstl.tlv.PermittedTaglibsTLV".START]

                      service jboss.deployment.subunit."PersonApp.ear"."PersonRest.war".component."javax.servlet.jsp.jstl.tlv.PermittedTaglibsTLV".START (missing) dependents: [service jboss.undertow.deployment.default-server.default-host./PersonRest.UndertowDeploymentInfoService, service jboss.undertow.deployment.default-server.default-host./PersonRest, service jboss.deployment.subunit."PersonApp.ear"."PersonRest.war".deploymentCompleteService]

                      service jboss.deployment.subunit."PersonApp.ear"."PersonRest.war".component."javax.servlet.jsp.jstl.tlv.ScriptFreeTLV".CREATE (missing) dependents: [service jboss.deployment.subunit."PersonApp.ear"."PersonRest.war".component."javax.servlet.jsp.jstl.tlv.ScriptFreeTLV".START]

                      service jboss.deployment.subunit."PersonApp.ear"."PersonRest.war".component."javax.servlet.jsp.jstl.tlv.ScriptFreeTLV".START (missing) dependents: [service jboss.undertow.deployment.default-server.default-host./PersonRest.UndertowDeploymentInfoService, service jboss.undertow.deployment.default-server.default-host./PersonRest, service jboss.deployment.subunit."PersonApp.ear"."PersonRest.war".deploymentCompleteService]

                      service jboss.deployment.subunit."PersonApp.ear"."PersonRest.war".component."javax.servlet.jsp.jstl.tlv.ScriptFreeTLV".WeldInstantiator (missing) dependents: [service jboss.deployment.subunit."PersonApp.ear"."PersonRest.war".component."javax.servlet.jsp.jstl.tlv.ScriptFreeTLV".START]

                      service jboss.deployment.subunit."PersonApp.ear"."PersonRest.war".component."org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher".START (missing) dependents: [service jboss.undertow.deployment.default-server.default-host./PersonRest.UndertowDeploymentInfoService, service jboss.undertow.deployment.default-server.default-host./PersonRest, service jboss.deployment.subunit."PersonApp.ear"."PersonRest.war".deploymentCompleteService]

                      service jboss.deployment.subunit."PersonApp.ear"."PersonRest.war".component."org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher".WeldInstantiator (missing) dependents: [service jboss.deployment.subunit."PersonApp.ear"."PersonRest.war".component."org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher".START]

                      service jboss.deployment.subunit."PersonApp.ear"."PersonRest.war".component."org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap".START (missing) dependents: [service jboss.undertow.deployment.default-server.default-host./PersonRest.UndertowDeploymentInfoService, service jboss.undertow.deployment.default-server.default-host./PersonRest, service jboss.deployment.subunit."PersonApp.ear"."PersonRest.war".deploymentCompleteService]

                      service jboss.deployment.subunit."PersonApp.ear"."PersonRest.war".component."org.jboss.weld.servlet.WeldInitialListener".CREATE (missing) dependents: [service jboss.deployment.subunit."PersonApp.ear"."PersonRest.war".component."org.jboss.weld.servlet.WeldInitialListener".START]

                      service jboss.deployment.subunit."PersonApp.ear"."PersonRest.war".component."org.jboss.weld.servlet.WeldInitialListener".START (missing) dependents: [service jboss.undertow.deployment.default-server.default-host./PersonRest.UndertowDeploymentInfoService, service jboss.undertow.deployment.default-server.default-host./PersonRest, service jboss.deployment.subunit."PersonApp.ear"."PersonRest.war".deploymentCompleteService]

                      service jboss.deployment.subunit."PersonApp.ear"."PersonRest.war".component."org.jboss.weld.servlet.WeldTerminalListener".CREATE (missing) dependents: [service jboss.deployment.subunit."PersonApp.ear"."PersonRest.war".component."org.jboss.weld.servlet.WeldTerminalListener".START]

                      service jboss.deployment.subunit."PersonApp.ear"."PersonRest.war".component."org.jboss.weld.servlet.WeldTerminalListener".START (missing) dependents: [service jboss.undertow.deployment.default-server.default-host./PersonRest.UndertowDeploymentInfoService, service jboss.undertow.deployment.default-server.default-host./PersonRest, service jboss.deployment.subunit."PersonApp.ear"."PersonRest.war".deploymentCompleteService]

                      service jboss.deployment.subunit."PersonApp.ear"."PersonRest.war".component."org.jboss.weld.servlet.WeldTerminalListener".WeldInstantiator (missing) dependents: [service jboss.deployment.subunit."PersonApp.ear"."PersonRest.war".component."org.jboss.weld.servlet.WeldTerminalListener".START]

                      service jboss.deployment.subunit."PersonApp.ear"."PersonRest.war".deploymentCompleteService (missing) dependents: [service jboss.deployment.unit."PersonApp.ear".deploymentCompleteService]

                      service jboss.deployment.subunit."PersonApp.ear"."PersonRest.war".ee.ComponentRegistry (missing) dependents: [service jboss.undertow.deployment.default-server.default-host./PersonRest.UndertowDeploymentInfoService]

                      service jboss.deployment.subunit."PersonApp.ear"."PersonRest.war".jndiDependencyService (missing) dependents: [service jboss.deployment.subunit."PersonApp.ear"."PersonRest.war".component."org.jboss.weld.servlet.WeldTerminalListener".START, service jboss.deployment.subunit."PersonApp.ear"."PersonRest.war".component."javax.faces.webapp.FacetTag".START, service jboss.deployment.subunit."PersonApp.ear"."PersonRest.war".component."javax.servlet.jsp.jstl.tlv.ScriptFreeTLV".START, service jboss.deployment.subunit."PersonApp.ear"."PersonRest.war".component."com.sun.faces.config.ConfigureListener".START]

                      service jboss.deployment.unit."PersonApp.ear".WeldBootstrapService (missing) dependents: [service jboss.deployment.unit."PersonApp.ear".CdiValidatorFactoryService]

                      service jboss.deployment.unit."PersonApp.ear".WeldStartService (missing) dependents: [service jboss.deployment.unit."PersonApp.ear".CdiValidatorFactoryService]

                      service jboss.persistenceunit."PersonApp.ear#PersonData" (missing) dependents: [service jboss.deployment.unit."PersonApp.ear".deploymentCompleteService]

                      service jboss.undertow.deployment.default-server.default-host./PersonRest (missing) dependents: [service jboss.deployment.subunit."PersonApp.ear"."PersonRest.war".deploymentCompleteService]

                      service jboss.undertow.deployment.default-server.default-host./PersonRest.UndertowDeploymentInfoService (missing) dependents: [service jboss.undertow.deployment.default-server.default-host./PersonRest]

                      service jboss.undertow.deployment.default-server.default-host./PersonRest.codec (missing) dependents: [service jboss.undertow.deployment.default-server.default-host./PersonRest.UndertowDeploymentInfoService]

                JBAS014777:   Services which failed to start:      service jboss.deployment.unit."PersonApp.ear".WeldStartService

                • 5. Re: Java, EntityManager always null when using JTA datasource
                  sfcoy

                  PersonData.jar needs to be specified as an EJB jar in your EAR's application.xml, otherwise your PersonManager SLSB will not be deployed as an EJB.

                  1 of 1 people found this helpful
                  • 6. Re: Java, EntityManager always null when using JTA datasource
                    dhileman

                    Thanks for your response.  I moved PersonData.jar out of the ear lib folder, and added it as an ejb module in application.xml.  This did resolve the DeploymentException, but unfortunately it put me back to the NullPointerException.  @Inject PersonManager manager isn't working.  manager turns up null.  The following shows up in the Wildfly startup output now, which was not there before:

                     

                    INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor]  (MSC service thread 1-1)  JNDI bindings for session bean named PersonManager in deployment subdeployment "PersonData.jar" of deployment "PersonApp.ear" are as follows:

                     

                         java:global/PersonApp/PersonData/PersonManager!com.csc.data.PersonManager

                         java:app/PersonData/PersonManager!com.csc.data.PersonManager

                         java:module/PersonManager!com.csc.data.PersonManager

                         java:global/PersonApp/PersonData/PersonManager

                         java:app/PersonData/PersonManager

                         java:module/PersonManager

                    -----------------------------------------

                    Summary so far:

                    • added @Inject private PersonManager manager; in PersonService.
                    • added @RequestScoped to PersonService
                    • added @Stateless to PersonManager

                    Adding those left me with the NullPointerException.  Manager was null. PersonManager Injection not working.

                    • deleted beans.xml since it is not needed with CDI 1.1/Java7

                    This left me with the DeploymentException (Unsatisfied dependencies at injection point)

                    • added PersonData as an ejb module in application.xml

                    This resolved the DeploymentException, but put me back to the NullPointerException with Injection of PersonManager not working

                     

                    -------------------------------------------

                    EDIT: Note: I have added a Servlet to my PersonRest project.  So now I have PersonService and PersonServlet.  In PersonServlet, Everything works flawlessly.  PersonManager injection works, and so does EntityManager transactions.

                     

                    So why might it work in my servlet, but not in my REST service?

                     

                    My servlet:

                    @WebServlet("/PersonServlet")
                    public class PersonServlet extends HttpServlet {
                         @Inject PersonManager manager;   //THIS WORKS - I can reference manager in the servlet doGet without issue
                    
                    
                    
                    
                    

                    My service:

                    @Path("/PersonService")
                    @RequestScoped
                    public class PersonService {
                         @Inject PersonManager manager; //THIS DOES NOT WORK - manager is null if I try to reference it in any service method
                    
                    
                    
                    
                    

                     

                    EDIT: for curiosity: If I remove @RequestScoped from PersonService, manager injection stops working in PersonServlet?? How can the service scope affect the servlet?  Really confused

                    #########################

                    EDIT: I finally found a solution.  I got the injection working in my REST service.  Here is what I did:

                    -Removed all references to RESTeasy from PersonRest web.xml

                    -Add @ApplicationPath("api") to my PersonRest Application

                    -Deleted the line "singletons.add(new PersonService());" from PersonRest Application.  No singletons added.

                     

                    All three things had to be done to get it working.  Can anyone explain to me why this worked?  Anyway, thank you hwellmann.de and sfcoy for your assistance.