0 Replies Latest reply on Oct 26, 2011 5:38 AM by oconnor

    PersistenceContext (EntityManager) - Could not inject members

    oconnor

      Hello I createt a simple Test:

      package bla.integration; 
      import javax.persistence.EntityManager;
      import javax.persistence.PersistenceContext;
      import javax.transaction.UserTransaction;
      
      import org.jboss.arquillian.container.test.api.Deployment;
      import org.jboss.arquillian.core.api.annotation.Inject;
      import org.jboss.arquillian.junit.Arquillian;
      import org.jboss.shrinkwrap.api.Archive;
      import org.jboss.shrinkwrap.api.ShrinkWrap;
      import org.jboss.shrinkwrap.api.asset.EmptyAsset;
      import org.jboss.shrinkwrap.api.spec.WebArchive;
      import org.junit.Test;
      import org.junit.runner.RunWith; 
      
      import bla.Azubi;
      
      
      @RunWith(Arquillian.class)
      public class SimpleTest
      {
         @Deployment
         public static Archive<?> createDeployment()
         {
            return ShrinkWrap.create(WebArchive.class, "test.war")
                  .addPackage(Azubi.class.getPackage())
                  .addAsManifestResource("META-INF/test-persistence.xml")
                  .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
         } 
         
         @PersistenceContext
         EntityManager em;
         
         @Inject
         UserTransaction utx;
      
      
         @Test
                public void simpleTesting() {
                          System.out.println("it works");
                }
      }
      

       

      If I use PersistenceContext for EntityManager I get following error message:

       

      11:27:41,483 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-5) Starting deployment of "test.war"
      11:27:41,525 INFO  [org.jboss.weld] (MSC service thread 1-7) Processing CDI deployment: test.war
      11:27:41,533 INFO  [org.jboss.weld] (MSC service thread 1-5) Starting Services for CDI deployment: test.war
      11:27:41,536 INFO  [org.jboss.weld] (MSC service thread 1-6) Starting weld service
      11:27:41,537 INFO  [org.jboss.as.arquillian] (MSC service thread 1-8) Arquillian deployment detected: ArquillianConfig[service=jboss.arquillian.config."test.war",unit=test.war,tests=[bla.integration.SimpleTest]]
      11:27:41,593 INFO  [org.jboss.web] (MSC service thread 1-7) registering web context: /test
      11:27:41,599 INFO  [org.jboss.as.server.controller] (pool-2-thread-1) Deployed "test.war"
      11:27:41,840 ERROR [org.jboss.arquillian.protocol.jmx.JMXTestRunner] (RMI TCP Connection(3)-127.0.0.1) Failed: bla.integration.SimpleTest.simpleTesting: java.lang.RuntimeException: Could not inject members
                at org.jboss.arquillian.testenricher.cdi.CDIInjectionEnricher.injectClass(CDIInjectionEnricher.java:135) [arquillian-service:]
                at org.jboss.arquillian.testenricher.cdi.CDIInjectionEnricher.enrich(CDIInjectionEnricher.java:78) [arquillian-service:]
                at org.jboss.arquillian.test.impl.TestInstanceEnricher.enrich(TestInstanceEnricher.java:52) [arquillian-service:]
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.6.0_25]
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [:1.6.0_25]
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [:1.6.0_25]
                at java.lang.reflect.Method.invoke(Method.java:597) [:1.6.0_25]
                at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:90) [arquillian-service:]
                at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99) [arquillian-service:]
                at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81) [arquillian-service:]
                at org.jboss.arquillian.test.impl.TestContextHandler.createTestContext(TestContextHandler.java:82) [arquillian-service:]
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.6.0_25]
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [:1.6.0_25]
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [:1.6.0_25]
                at java.lang.reflect.Method.invoke(Method.java:597) [:1.6.0_25]
                at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:90) [arquillian-service:]
                at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88) [arquillian-service:]
                at org.jboss.arquillian.test.impl.TestContextHandler.createClassContext(TestContextHandler.java:68) [arquillian-service:]
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.6.0_25]
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [:1.6.0_25]
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [:1.6.0_25]
                at java.lang.reflect.Method.invoke(Method.java:597) [:1.6.0_25]
                at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:90) [arquillian-service:]
                at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88) [arquillian-service:]
                at org.jboss.arquillian.test.impl.TestContextHandler.createSuiteContext(TestContextHandler.java:54) [arquillian-service:]
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.6.0_25]
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [:1.6.0_25]
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [:1.6.0_25]
                at java.lang.reflect.Method.invoke(Method.java:597) [:1.6.0_25]
                at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:90) [arquillian-service:]
                at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88) [arquillian-service:]
                at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:134) [arquillian-service:]
                at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:114) [arquillian-service:]
                at org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.before(EventTestRunnerAdaptor.java:95) [arquillian-service:]
                at org.jboss.arquillian.junit.Arquillian$4.evaluate(Arquillian.java:198) [arquillian-service:]
                at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:290) [arquillian-service:]
                at org.jboss.arquillian.junit.Arquillian.access$0(Arquillian.java:283) [arquillian-service:]
                at org.jboss.arquillian.junit.Arquillian$5.evaluate(Arquillian.java:216) [arquillian-service:]
                at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79) [arquillian-service:]
                at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71) [arquillian-service:]
                at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49) [arquillian-service:]
                at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193) [arquillian-service:]
                at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52) [arquillian-service:]
                at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191) [arquillian-service:]
                at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42) [arquillian-service:]
                at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184) [arquillian-service:]
                at org.jboss.arquillian.junit.Arquillian$2.evaluate(Arquillian.java:161) [arquillian-service:]
                at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:290) [arquillian-service:]
                at org.jboss.arquillian.junit.Arquillian.access$0(Arquillian.java:283) [arquillian-service:]
                at org.jboss.arquillian.junit.Arquillian$3.evaluate(Arquillian.java:175) [arquillian-service:]
                at org.junit.runners.ParentRunner.run(ParentRunner.java:236) [arquillian-service:]
                at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:123) [arquillian-service:]
                at org.junit.runner.JUnitCore.run(JUnitCore.java:157) [arquillian-service:]
                at org.junit.runner.JUnitCore.run(JUnitCore.java:136) [arquillian-service:]
                at org.jboss.arquillian.junit.container.JUnitTestRunner.execute(JUnitTestRunner.java:65) [arquillian-service:]
                at org.jboss.arquillian.protocol.jmx.JMXTestRunner.runTestMethodInternal(JMXTestRunner.java:128) [arquillian-service:]
                at org.jboss.arquillian.protocol.jmx.JMXTestRunner.runTestMethod(JMXTestRunner.java:107) [arquillian-service:]
                at org.jboss.as.arquillian.service.ArquillianService$ExtendedJMXTestRunner.runTestMethod(ArquillianService.java:203) [arquillian-service:]
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.6.0_25]
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [:1.6.0_25]
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [:1.6.0_25]
                at java.lang.reflect.Method.invoke(Method.java:597) [:1.6.0_25]
                at com.sun.jmx.mbeanserver.StandardMBeanIntrospector.invokeM2(StandardMBeanIntrospector.java:93) [:1.6.0_25]
                at com.sun.jmx.mbeanserver.StandardMBeanIntrospector.invokeM2(StandardMBeanIntrospector.java:27) [:1.6.0_25]
                at com.sun.jmx.mbeanserver.MBeanIntrospector.invokeM(MBeanIntrospector.java:208) [:1.6.0_25]
                at com.sun.jmx.mbeanserver.PerInterface.invoke(PerInterface.java:120) [:1.6.0_25]
                at com.sun.jmx.mbeanserver.MBeanSupport.invoke(MBeanSupport.java:262) [:1.6.0_25]
                at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:836) [:1.6.0_25]
                at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:761) [:1.6.0_25]
                at org.jboss.as.jmx.tcl.TcclMBeanServer.invoke(TcclMBeanServer.java:218)
                at org.jboss.as.jmx.model.ModelControllerMBeanServer.invoke(ModelControllerMBeanServer.java:202)
                at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1427) [:1.6.0_25]
                at javax.management.remote.rmi.RMIConnectionImpl.access$200(RMIConnectionImpl.java:72) [:1.6.0_25]
                at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1265) [:1.6.0_25]
                at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1360) [:1.6.0_25]
                at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:788) [:1.6.0_25]
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.6.0_25]
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [:1.6.0_25]
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [:1.6.0_25]
                at java.lang.reflect.Method.invoke(Method.java:597) [:1.6.0_25]
                at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:305) [:1.6.0_25]
                at sun.rmi.transport.Transport$1.run(Transport.java:159) [:1.6.0_25]
                at java.security.AccessController.doPrivileged(Native Method) [:1.6.0_25]
                at sun.rmi.transport.Transport.serviceCall(Transport.java:155) [:1.6.0_25]
                at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535) [:1.6.0_25]
                at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790) [:1.6.0_25]
                at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649) [:1.6.0_25]
                at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_25]
                at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_25]
                at java.lang.Thread.run(Thread.java:662) [:1.6.0_25]
      Caused by: java.lang.RuntimeException: Can't find a deployment unit named  at deployment "test.war"
                at org.jboss.as.weld.services.bootstrap.WeldJpaInjectionServices.getScopedPUName(WeldJpaInjectionServices.java:94) [jboss-as-weld-7.1.0.Alpha2-SNAPSHOT.jar:7.1.0.Alpha2-SNAPSHOT]
                at org.jboss.as.weld.services.bootstrap.WeldJpaInjectionServices.resolvePersistenceContext(WeldJpaInjectionServices.java:59) [jboss-as-weld-7.1.0.Alpha2-SNAPSHOT.jar:7.1.0.Alpha2-SNAPSHOT]
                at org.jboss.weld.util.Beans.injectEEFields(Beans.java:784) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]
                at org.jboss.weld.manager.SimpleInjectionTarget$1.proceed(SimpleInjectionTarget.java:119) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]
                at org.jboss.weld.injection.InjectionContextImpl.run(InjectionContextImpl.java:54) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]
                at org.jboss.weld.manager.SimpleInjectionTarget.inject(SimpleInjectionTarget.java:114) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]
                at org.jboss.arquillian.testenricher.cdi.CDIInjectionEnricher.injectNonContextualInstance(CDIInjectionEnricher.java:145) [arquillian-service:]
                at org.jboss.arquillian.testenricher.cdi.CDIInjectionEnricher.injectClass(CDIInjectionEnricher.java:125) [arquillian-service:]
                ... 89 more
      
      
      11:27:41,894 INFO  [org.jboss.weld] (MSC service thread 1-6) Stopping weld service
      11:27:41,896 INFO  [org.jboss.as.server.controller] (pool-2-thread-1) Undeployed "test.war"
      11:27:41,914 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-3) Stopped deployment test.war in 24ms
      11:27:41,928 INFO  [org.jboss.as.osgi] (MSC service thread 1-3) JBAS011922: Unregister module: Module "deployment.arquillian-service:main" from Service Module Loader
      11:27:41,928 ERROR [org.jboss.osgi.framework.internal.BundleManager] (MSC service thread 1-3) Cannot find bundle associated with module: deployment.arquillian-service:main
      11:27:41,931 INFO  [org.jboss.as.server.controller] (pool-2-thread-1) Undeployed "arquillian-service"
      11:27:41,932 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-6) Stopped deployment arquillian-service in 6ms