3 Replies Latest reply on Jan 6, 2011 12:20 PM by Aslak Knutsen

    JPA and Weld-Embedded EE 1.1 doesn't work

    Ove Ranheim Novice

      Hi,

       

      I'm not able to have weld-embbed create the entity manager factory, hence not able to test JPA with org.jboss.weld.arquillian.container:arquillian-weld-ee-embedded-1.1:1.1.0.CR4.

       

      What may be the cause here. Tried to make an EntityManagerFactory producer and create it manually, but then it complain it can't find the persistence unit ("primary").

       

      As far as I can see, my configuration looks right.

       

      Weld-embedded-1.1 profile configuration:

       

           http://pastebin.com/NC1K6tCD

       

      and here is the dependency graph:

       

           http://pastebin.com/ByKsMUBG

       

      Simple test case:

       

      @RunWith(Arquillian.class)
      public class UserDomainTest {
      
          @Deployment
          public static WebArchive createTestArchive() {
              return ShrinkWrap.create(WebArchive.class, "test.war")
                      .addClasses(org.slf4j.impl.Log4jLoggerAdapter.class,
                              org.slf4j.impl.Log4jLoggerFactory.class,
                              org.slf4j.impl.Log4jMDCAdapter.class,
                              org.slf4j.impl.StaticLoggerBinder.class,
                              org.slf4j.impl.StaticMarkerBinder.class,
                              org.slf4j.impl.StaticMDCBinder.class)
                      .addClasses(PartsDatabase.class, PartsRepositoryProducer.class, LogWrapper.class)
                      .addWebResource("test-persistence.xml", "classes/META-INF/persistence.xml")
                      .addWebResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml"))
                      .addManifestResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml"));
              
          }
      
          @Inject
          LogWrapper log;
          //Instance<Logger> log;
      
          @Inject
          @PartsDatabase
          EntityManager em;
      
          @Test
          public void testEntityManager() throws Exception {
              assertNotNull( em );
          }
      
          @Test
          public void testEntityManagerFactory() throws Exception {
              assertNotNull( em.getEntityManagerFactory() );        // <======== fails
          }
      
      }
      

       

       

      Exception log:

       

      testEntityManagerFactory(eris.services.test.model.UserDomainTest)  Time elapsed: 0.011 sec  <<< ERROR!
      org.jboss.weld.exceptions.NullInstanceException: WELD-000044 Unable to obtain instance from null
              at org.jboss.weld.bean.builtin.CallableMethodHandler.invoke(CallableMethodHandler.java:53)
              at org.jboss.weld.bean.proxy.EnterpriseTargetBeanInstance.invoke(EnterpriseTargetBeanInstance.java:62)
              at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:125)
              at org.jboss.weldx.persistence.org$jboss$weld$bean-test$war-ProducerField-eris$services$data$PartsRepositoryProducer$em_$$_WeldProxy.getEntityManagerFactory(org$jboss$weld$bean-test$war-ProducerField-eris$services$data$PartsRepositoryProducer$em_$$_WeldProxy.java)
              at eris.services.test.model.UserDomainTest.testEntityManagerFactory(UserDomainTest.java:180)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:597)
              at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
              at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
              at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
              at org.jboss.arquillian.junit.Arquillian$6$1.invoke(Arquillian.java:251)
              at org.jboss.arquillian.protocol.local.LocalMethodExecutor.invoke(LocalMethodExecutor.java:40)
              at org.jboss.arquillian.impl.handler.ContainerTestExecuter.callback(ContainerTestExecuter.java:50)
              at org.jboss.arquillian.impl.handler.ContainerTestExecuter.callback(ContainerTestExecuter.java:40)
              at org.jboss.arquillian.impl.event.MapEventManager.fire(MapEventManager.java:63)
              at org.jboss.arquillian.impl.context.AbstractEventContext.fire(AbstractEventContext.java:115)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:597)
              at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
              at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
              at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
              at org.jboss.arquillian.junit.Arquillian$6$1.invoke(Arquillian.java:251)
              at org.jboss.arquillian.protocol.local.LocalMethodExecutor.invoke(LocalMethodExecutor.java:40)
              at org.jboss.arquillian.impl.handler.ContainerTestExecuter.callback(ContainerTestExecuter.java:50)
              at org.jboss.arquillian.impl.handler.ContainerTestExecuter.callback(ContainerTestExecuter.java:40)
              at org.jboss.arquillian.impl.event.MapEventManager.fire(MapEventManager.java:63)
              at org.jboss.arquillian.impl.context.AbstractEventContext.fire(AbstractEventContext.java:115)
              at org.jboss.arquillian.impl.EventTestRunnerAdaptor.test(EventTestRunnerAdaptor.java:157)
              at org.jboss.arquillian.junit.Arquillian$6.evaluate(Arquillian.java:244)
              at org.jboss.arquillian.junit.Arquillian$4.evaluate(Arquillian.java:207)
              at org.jboss.arquillian.junit.Arquillian$5$1.evaluate(Arquillian.java:225)
              at org.jboss.arquillian.junit.Arquillian$MultiStatementExecutor.execute(Arquillian.java:297)
              at org.jboss.arquillian.junit.Arquillian$5.evaluate(Arquillian.java:221)
              at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
              at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
              at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
              at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
              at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
              at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
              at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
              at org.jboss.arquillian.junit.Arquillian$2.evaluate(Arquillian.java:163)
      (..cut.. no root cause)
      

       

       

      Can't figure out what's wrong here!?

       

      Br, Ove

        • 1. Re: JPA and Weld-Embedded EE 1.1 doesn't work
          Aslak Knutsen Master

          The Weld Embedded EE container is just a Weld 'SE' Container with active Contexts and Mock EE APIs. You need to deploy against a full container to get the integrations between JPA and CDI.

           

          I think you should be able to deploy your own EntityManager producer tho, for the sake of the test. How did you create it?

          1 of 1 people found this helpful
          • 2. Re: JPA and Weld-Embedded EE 1.1 doesn't work
            Ove Ranheim Novice

            Ok. I see.

             

            Does it make sense to run test in the weld-embedded-ee-1.1 then? What I'm after is a light weight way to running JPA and CDI Bean tests, and transparently have test cases capable of running in the jbossas-remote-6. Is the weld embedded good enough for such purposes?

             

            @Singleton
            public class WeldRepositoryProducer {
            
                private static EntityManagerFactory factory;
            
                @Produces
                public EntityManagerFactory getEntityManagerFactory() {
                    if (factory == null) {
                        factory = Persistence.createEntityManagerFactory("primary");
                    }
                    return factory;
                }
            
                @Produces
                @PartsDatabase
                @ConversationScoped
                public EntityManager produceEntityManager() {
                    return getEntityManagerFactory().createEntityManager();
                }
            
            }
            

             

             

            and a minor change in ShrinkWrap where PartsRepositoryProducer is replace with the WeldRepositoryProducer.

             

            .addClasses(PartsDatabase.class, WeldRepositoryProducer.class, LogWrapper.class)
            

             

            Exception log

             

            -------------------------------------------------------------------------------
            Test set: eris.services.test.model.UserDomainTest                
            -------------------------------------------------------------------------------
            Tests run: 13, Failures: 0, Errors: 12, Skipped: 0, Time elapsed: 8.107 sec <<< FAILURE!
            testEntityManagerFactory(eris.services.test.model.UserDomainTest)  Time elapsed: 1.094 sec  <<< ERROR!
            javax.persistence.PersistenceException: No Persistence provider for EntityManager named primary
                    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
                    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:32)
                    at eris.services.test.logic.WeldRepositoryProducer.getEntityManagerFactory(WeldRepositoryProducer.java:20)
                    at eris.services.test.logic.WeldRepositoryProducer.produceEntityManager(WeldRepositoryProducer.java:29)
                    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                    at java.lang.reflect.Method.invoke(Method.java:597)
                    at org.jboss.weld.util.reflection.SecureReflections$13.work(SecureReflections.java:305)
                    at org.jboss.weld.util.reflection.SecureReflectionAccess.run(SecureReflectionAccess.java:54)
                    at org.jboss.weld.util.reflection.SecureReflectionAccess.runAsInvocation(SecureReflectionAccess.java:163)
                    at org.jboss.weld.util.reflection.SecureReflections.invoke(SecureReflections.java:299)
                    at org.jboss.weld.introspector.jlr.WeldMethodImpl.invokeOnInstance(WeldMethodImpl.java:188)
                    at org.jboss.weld.injection.MethodInjectionPoint.invokeOnInstance(MethodInjectionPoint.java:169)
                    at org.jboss.weld.bean.ProducerMethod$1.produce(ProducerMethod.java:149)
                    at org.jboss.weld.bean.AbstractProducerBean.create(AbstractProducerBean.java:361)
                    at org.jboss.weld.context.AbstractContext.get(AbstractContext.java:121)
                    at org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:99)
                    at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:124)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                    at java.lang.reflect.Method.invoke(Method.java:597)
                    at org.jboss.weld.util.reflection.SecureReflections$13.work(SecureReflections.java:305)
                    at org.jboss.weld.util.reflection.SecureReflectionAccess.run(SecureReflectionAccess.java:54)
                    at org.jboss.weld.util.reflection.SecureReflectionAccess.runAsInvocation(SecureReflectionAccess.java:163)
                    at org.jboss.weld.util.reflection.SecureReflections.invoke(SecureReflections.java:299)
                    at org.jboss.weld.introspector.jlr.WeldMethodImpl.invokeOnInstance(WeldMethodImpl.java:188)
                    at org.jboss.weld.injection.MethodInjectionPoint.invokeOnInstance(MethodInjectionPoint.java:169)
                    at org.jboss.weld.bean.ProducerMethod$1.produce(ProducerMethod.java:149)
                    at org.jboss.weld.bean.AbstractProducerBean.create(AbstractProducerBean.java:361)
                    at org.jboss.weld.context.AbstractContext.get(AbstractContext.java:121)
                    at org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:99)
                    at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:124)
                    at org.jboss.weld.proxies.org$jboss$weld$beanProducerMethod-eris$services$test$logic$WeldRepositoryProducermethod_produceEntityManager()_$$_WeldClientProxy.getEntityManagerFactory(org$jboss$weld$beanProducerMethod-eris$services$test$logic$WeldRepositoryProducermethod_produceEntityManager()_$$_WeldClientProxy.java)
                    at eris.services.test.model.UserDomainTest.testEntityManagerFactory(UserDomainTest.java:180)
                    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                    at java.lang.reflect.Method.invoke(Method.java:597)
                    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
                    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
                    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
                    at org.jboss.arquillian.junit.Arquillian$6$1.invoke(Arquillian.java:251)
                    at org.jboss.arquillian.protocol.local.LocalMethodExecutor.invoke(LocalMethodExecutor.java:40)
            (..cut..)
            
            • 3. Re: JPA and Weld-Embedded EE 1.1 doesn't work
              Aslak Knutsen Master

              You do need to add a entitymanager impl to you classpath, e.g. hibernate-entitymanager.