5 Replies Latest reply on Mar 28, 2011 1:10 PM by Aslak Knutsen

    Persistence Context is null

    Ryan Cuprak Newbie

      I am having some trouble acquiring a persistence context. Instead of the context I get: IllegalStateException: Unable to retrieve EntityManagerFactory for unitName null. My web.xml and code for generating the persistence.xml is below. The data source is configured in domain.xml file (which I pulled from the instance of Glassfish I use to run the application). I am not seeing any error messages on the console about the datasource (or any messages at all). About the only thing I can think of is that the embedded glassfish container is missing the Postgresql JDBC driver but I am not sure how to prove this.  

       

      web.xml

      <?xml version="1.0" encoding="UTF-8"?>
      <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
          <resource-ref>
              <res-ref-name>jdbc/ctjug</res-ref-name>
              <res-type>javax.sql.DataSource</res-type>
              <res-auth>Container</res-auth>
          </resource-ref> 
      </web-app>
      
      

       

      Code generating persistence.xml:

       

      ws.addAsManifestResource(new StringAsset(
                              Descriptors.create(PersistenceDescriptor.class)
                                      .persistenceUnit("ctjug")
                                      .provider("oracle.toplink.essentials.PersistenceProvider")
                                      .transactionType(TransactionType.JTA)
                                      .excludeUnlistedClasses()
                                      .jtaDataSource("jdbc/ctjug")
                                      .schemaGenerationMode(SchemaGenerationModeType.CREATE_DROP)
                                      .exportAsString()), "persistence.xml");
      wa.addAsWebInfResource(new File("src/test/resources/web.xml"),"web.xml");
      
      

       

       

      Exception:

      WARNING: A system exception occurred during an invocation on EJB SpeakerService method public void org.ctjava.services.SpeakerService.createSpeaker(org.ctjava.model.Speaker)
      javax.ejb.EJBException
           at com.sun.ejb.containers.BaseContainer.processSystemException(BaseContainer.java:5194)
           at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:5092)
           at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4880)
           at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2039)
           at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1990)
           at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:222)
           at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:88)
           at $Proxy123.createSpeaker(Unknown Source)
           at org.ctjava.services.__EJB31_Generated__SpeakerService__Intf____Bean__.createSpeaker(Unknown Source)
           at org.ctjava.services.TestSpeakerService.testCreateSpeaker(TestSpeakerService.java:80)
           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:259)
           at org.jboss.arquillian.impl.execution.LocalTestExecuter.execute(LocalTestExecuter.java:63)
           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)
      ...
      
      
        • 1. Persistence Context is null
          Aslak Knutsen Master

          Where is IllegalState thrown from? stacktrace?

           

          There are no startup errors at all from GlassFish ?

          • 2. Re: Persistence Context is null
            Ryan Cuprak Newbie

            Full output from the run is below.

            Note, I added some debug logic to my test to print out the paths of various things and content. I dump the contents of the persistence.xml from the classpath to the console so that I could verify it was in the correct place and had the expected values etc.

             

            -Ryan

             

            -------------------------------------------------------
             T E S T S
            -------------------------------------------------------
            Running org.ctjava.services.TestSpeakerService
            Mar 26, 2011 6:51:41 PM org.jboss.arquillian.impl.client.container.ContainerRegistryCreator getActivatedConfiguration
            INFO: Could not read active container configuration: null
            Mar 26, 2011 6:51:43 PM com.sun.enterprise.v3.server.CommonClassLoaderServiceImpl findDerbyClient
            INFO: Cannot find javadb client jar file, derby jdbc driver will not be available by default.
            Mar 26, 2011 6:51:44 PM org.hibernate.validator.util.Version <clinit>
            INFO: Hibernate Validator null
            Mar 26, 2011 6:51:44 PM org.hibernate.validator.engine.resolver.DefaultTraversableResolver detectJPA
            INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
            Mar 26, 2011 6:51:44 PM com.sun.enterprise.v3.services.impl.GrizzlyProxy$2$1 onReady
            INFO: Grizzly Framework 1.9.31 started in: 102ms - bound to [0.0.0.0:3700]
            Mar 26, 2011 6:51:44 PM com.sun.enterprise.v3.services.impl.GrizzlyProxy$2$1 onReady
            INFO: Grizzly Framework 1.9.31 started in: 123ms - bound to [0.0.0.0:4848]
            Mar 26, 2011 6:51:44 PM com.sun.enterprise.v3.services.impl.GrizzlyProxy$2$1 onReady
            INFO: Grizzly Framework 1.9.31 started in: 83ms - bound to [0.0.0.0:7676]
            Mar 26, 2011 6:51:44 PM com.sun.enterprise.v3.services.impl.GrizzlyProxy$2$1 onReady
            INFO: Grizzly Framework 1.9.31 started in: 136ms - bound to [0.0.0.0:8181]
            Mar 26, 2011 6:51:44 PM com.sun.enterprise.v3.server.AppServerStartup run
            INFO: GlassFish Server Open Source Edition 3.1 (java_re-private) startup time : Embedded (978ms), startup services(572ms), total(1,550ms)
            -----------------------
            /Users/rcuprak/Projects/ctjava/ctjava/src/main/webapp/web.xml
            -----------------------
            Mar 26, 2011 6:51:45 PM org.glassfish.admin.mbeanserver.JMXStartupService$JMXConnectorsStarterThread startConnector
            INFO: JMXStartupService: Started JMXConnector, JMXService URL = service:jmx:rmi://192.168.5.170:8686/jndi/rmi://192.168.5.170:8686/jmxrmi
            Mar 26, 2011 6:51:47 PM com.sun.enterprise.security.SecurityLifecycle <init>
            INFO: SEC1002: Security Manager is OFF.
            Mar 26, 2011 6:51:47 PM com.sun.enterprise.security.SecurityLifecycle onInitialization
            INFO: SEC1010: Entering Security Startup Service
            Mar 26, 2011 6:51:47 PM com.sun.enterprise.security.PolicyLoader loadPolicy
            INFO: SEC1143: Loading policy provider com.sun.enterprise.security.provider.PolicyWrapper.
            Mar 26, 2011 6:51:47 PM com.sun.enterprise.security.auth.realm.Realm doInstantiate
            INFO: SEC1115: Realm [admin-realm] of classtype [com.sun.enterprise.security.auth.realm.file.FileRealm] successfully created.
            Mar 26, 2011 6:51:47 PM com.sun.enterprise.security.auth.realm.Realm doInstantiate
            INFO: SEC1115: Realm [file] of classtype [com.sun.enterprise.security.auth.realm.file.FileRealm] successfully created.
            Mar 26, 2011 6:51:47 PM com.sun.enterprise.security.auth.realm.Realm doInstantiate
            INFO: SEC1115: Realm [certificate] of classtype [com.sun.enterprise.security.auth.realm.certificate.CertificateRealm] successfully created.
            Mar 26, 2011 6:51:47 PM com.sun.enterprise.security.SecurityLifecycle onInitialization
            INFO: SEC1011: Security Service(s) Started Successfully
            Mar 26, 2011 6:51:48 PM com.sun.enterprise.web.WebContainer createHttpListener
            INFO: WEB0169: Created HTTP listener [http-listener] on host/port [0.0.0.0:8181]
            Mar 26, 2011 6:51:48 PM com.sun.enterprise.web.WebContainer createHttpListener
            INFO: WEB0169: Created HTTP listener [admin-listener] on host/port [0.0.0.0:4848]
            Mar 26, 2011 6:51:48 PM com.sun.enterprise.web.WebContainer createHosts
            INFO: WEB0171: Created virtual server [server]
            Mar 26, 2011 6:51:48 PM com.sun.enterprise.web.WebContainer createHosts
            INFO: WEB0171: Created virtual server [__asadmin]
            Mar 26, 2011 6:51:48 PM com.sun.enterprise.web.WebContainer loadSystemDefaultWebModules
            INFO: WEB0172: Virtual server [server] loaded default web module []
            classLoader = WebappClassLoader (delegate=true; repositories=WEB-INF/classes/)
            SharedSecrets.getJavaNetAccess()=java.net.URLClassLoader$7@1db4b415
            Mar 26, 2011 6:51:50 PM com.sun.ejb.containers.BaseContainer initializeHome
            INFO: Portable JNDI names for EJB SpeakerService : [java:global/test/SpeakerService!org.ctjava.services.SpeakerService, java:global/test/SpeakerService]
            Mar 26, 2011 6:51:50 PM com.sun.faces.config.ConfigureListener contextInitialized
            INFO: Initializing Mojarra 2.1.0 (FCS 2.1.0-b11) for context '/test'
            Mar 26, 2011 6:51:52 PM com.sun.enterprise.web.WebApplication start
            INFO: WEB0671: Loading application [test] at [/test]
            Mar 26, 2011 6:51:52 PM org.glassfish.deployment.admin.DeployCommand execute
            INFO: test was successfully deployed in 6,266 milliseconds.
            PlainTextActionReporterSUCCESSDescription: deploy AdminCommandApplication deployed with name test.
                [name=test
            Mar 26, 2011 6:51:53 PM org.jboss.arquillian.testenricher.cdi.CDIInjectionEnricher injectClass
            INFO: BeanManager cannot be located at java:comp/BeanManager. Either you are using an archive with no beans.xml, or the BeanManager has not been bound to that location in JNDI.
            -----
            CONTENT: java.io.BufferedInputStream@44408caa
            <?xml version="1.0" encoding="UTF-8"?>
            <persistence version="1.0" 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">
              <persistence-unit name="ctjug" transaction-type="JTA">
                <jta-data-source>jdbc/ctjug</jta-data-source>
                <properties>
                    <property name="toplink.ddl-generation" value="drop-and-create-tables"/>
                </properties>
              </persistence-unit>
            </persistence>
            -----
            Mar 26, 2011 6:51:53 PM com.sun.ejb.containers.BaseContainer postInvoke
            WARNING: A system exception occurred during an invocation on EJB SpeakerService method public void org.ctjava.services.SpeakerService.createSpeaker(org.ctjava.model.Speaker)
            javax.ejb.EJBException
                      at com.sun.ejb.containers.BaseContainer.processSystemException(BaseContainer.java:5194)
                      at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:5092)
                      at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4880)
                      at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2039)
                      at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1990)
                      at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:222)
                      at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:88)
                      at $Proxy123.createSpeaker(Unknown Source)
                      at org.ctjava.services.__EJB31_Generated__SpeakerService__Intf____Bean__.createSpeaker(Unknown Source)
                      at org.ctjava.services.TestSpeakerService.testCreateSpeaker(TestSpeakerService.java:80)
                      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:259)
                      at org.jboss.arquillian.impl.execution.LocalTestExecuter.execute(LocalTestExecuter.java:63)
                      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.arquillian.impl.core.ObserverImpl.invoke(ObserverImpl.java:90)
                      at org.jboss.arquillian.impl.core.EventContextImpl.invokeObservers(EventContextImpl.java:98)
                      at org.jboss.arquillian.impl.core.EventContextImpl.proceed(EventContextImpl.java:80)
                      at org.jboss.arquillian.impl.core.ManagerImpl.fire(ManagerImpl.java:126)
                      at org.jboss.arquillian.impl.core.ManagerImpl.fire(ManagerImpl.java:106)
                      at org.jboss.arquillian.impl.core.EventImpl.fire(EventImpl.java:67)
                      at org.jboss.arquillian.impl.execution.ContainerTestExecuter.execute(ContainerTestExecuter.java:38)
                      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.arquillian.impl.core.ObserverImpl.invoke(ObserverImpl.java:90)
                      at org.jboss.arquillian.impl.core.EventContextImpl.invokeObservers(EventContextImpl.java:98)
                      at org.jboss.arquillian.impl.core.EventContextImpl.proceed(EventContextImpl.java:80)
                      at org.jboss.arquillian.impl.TestContextHandler.createTestContext(TestContextHandler.java:82)
                      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.arquillian.impl.core.ObserverImpl.invoke(ObserverImpl.java:90)
                      at org.jboss.arquillian.impl.core.EventContextImpl.proceed(EventContextImpl.java:87)
                      at org.jboss.arquillian.impl.TestContextHandler.createClassContext(TestContextHandler.java:68)
                      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.arquillian.impl.core.ObserverImpl.invoke(ObserverImpl.java:90)
                      at org.jboss.arquillian.impl.core.EventContextImpl.proceed(EventContextImpl.java:87)
                      at org.jboss.arquillian.impl.TestContextHandler.createSuiteContext(TestContextHandler.java:54)
                      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.arquillian.impl.core.ObserverImpl.invoke(ObserverImpl.java:90)
                      at org.jboss.arquillian.impl.core.EventContextImpl.proceed(EventContextImpl.java:87)
                      at org.jboss.arquillian.impl.core.ManagerImpl.fire(ManagerImpl.java:126)
                      at org.jboss.arquillian.impl.EventTestRunnerAdaptor.test(EventTestRunnerAdaptor.java:101)
                      at org.jboss.arquillian.junit.Arquillian$6.evaluate(Arquillian.java:251)
                      at org.jboss.arquillian.junit.Arquillian$4.evaluate(Arquillian.java:214)
                      at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:303)
                      at org.jboss.arquillian.junit.Arquillian.access$300(Arquillian.java:45)
                      at org.jboss.arquillian.junit.Arquillian$5.evaluate(Arquillian.java:228)
                      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:173)
                      at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:303)
                      at org.jboss.arquillian.junit.Arquillian.access$300(Arquillian.java:45)
                      at org.jboss.arquillian.junit.Arquillian$3.evaluate(Arquillian.java:187)
                      at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
                      at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:127)
                      at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
                      at org.junit.runner.JUnitCore.run(JUnitCore.java:136)
                      at org.jboss.arquillian.junit.JUnitTestRunner.execute(JUnitTestRunner.java:69)
                      at org.jboss.arquillian.protocol.servlet.runner.ServletTestRunner.doGet(ServletTestRunner.java:84)
                      at javax.servlet.http.HttpServlet.service(HttpServlet.java:735)
                      at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
                      at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1534)
                      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
                      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
                      at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
                      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
                      at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)
                      at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)
                      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)
                      at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:326)
                      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:227)
                      at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:170)
                      at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:822)
                      at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:719)
                      at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1013)
                      at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
                      at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
                      at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
                      at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
                      at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
                      at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
                      at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
                      at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
                      at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
                      at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
                      at java.lang.Thread.run(Thread.java:680)
            Caused by: java.lang.IllegalStateException: Unable to retrieve EntityManagerFactory for unitName null
                      at com.sun.enterprise.container.common.impl.EntityManagerWrapper.init(EntityManagerWrapper.java:132)
                      at com.sun.enterprise.container.common.impl.EntityManagerWrapper.doTxRequiredCheck(EntityManagerWrapper.java:152)
                      at com.sun.enterprise.container.common.impl.EntityManagerWrapper.doTransactionScopedTxCheck(EntityManagerWrapper.java:145)
                      at com.sun.enterprise.container.common.impl.EntityManagerWrapper.persist(EntityManagerWrapper.java:263)
                      at org.ctjava.services.SpeakerService.createSpeaker(SpeakerService.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.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1052)
                      at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1124)
                      at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:5367)
                      at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:619)
                      at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:801)
                      at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:571)
                      at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doAround(SystemInterceptorProxy.java:162)
                      at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:144)
                      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 com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:862)
                      at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:801)
                      at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:371)
                      at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:5339)
                      at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:5327)
                      at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:214)
                      ... 103 more
            Mar 26, 2011 6:51:53 PM com.sun.faces.lifecycle.ELResolverInitPhaseListener populateFacesELResolverForJsp
            INFO: JSF1027: [null] The ELResolvers for JSF were not registered with the JSP container.
            classLoader = WebappClassLoader (delegate=true; repositories=WEB-INF/classes/)
            SharedSecrets.getJavaNetAccess()=java.net.URLClassLoader$7@1db4b415
            PlainTextActionReporterSUCCESSNo monitoring data to report.
            Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 12.142 sec <<< FAILURE!
            
            
            Results :
            
            
            Tests in error: 
              testCreateSpeaker(org.ctjava.services.TestSpeakerService)
            
            
            Tests run: 1, Failures: 0, Errors: 1, Skipped: 0
            
            
            
            • 3. Re: Persistence Context is null
              Aslak Knutsen Master

              Hmm, could you post the full source of TestSpeakerService and SpeakerService ?

              • 4. Re: Persistence Context is null
                Ryan Cuprak Newbie

                Certainly - there isn't much to it right now.

                 

                 

                @RunWith(Arquillian.class)
                public class TestSpeakerService {
                
                
                    /**
                     * Speaker service
                     */
                    @EJB
                    private SpeakerService speakerService;
                
                
                    /**
                     * Creates a deploym    ent item.
                     * @return ShrinkWrap
                     */
                    @Deployment(name="glassfish",testable = true)
                    public static WebArchive createDeployment() {
                        System.out.println("-----------------------");
                        System.out.println(new File("src/main/webapp/web.xml").getAbsolutePath());
                        System.out.println("-----------------------");
                        WebArchive wa =  ShrinkWrap.create(WebArchive.class, "test.jar").addPackage(SpeakerService.class.getPackage())
                                .addPackage(Speaker.class.getPackage()).addAsManifestResource(new StringAsset(
                                        Descriptors.create(PersistenceDescriptor.class)
                                                .persistenceUnit("ctjug")
                                                .provider("oracle.toplink.essentials.PersistenceProvider")
                                                .transactionType(TransactionType.JTA)
                                                .excludeUnlistedClasses()
                                                .jtaDataSource("jdbc/ctjug")
                                                .schemaGenerationMode(SchemaGenerationModeType.CREATE_DROP)
                                                .exportAsString()), "persistence.xml");
                
                
                        wa.addAsWebInfResource(new File("src/test/resources/web.xml"),"web.xml");
                
                
                        return wa;
                    }
                
                
                    /**
                     * Tests creation of a speaker
                     */
                    @Test
                    @OperateOnDeployment("glassfish")
                    public void testCreateSpeaker() throws Exception {
                        InputStream is = getClass().getResourceAsStream("/META-INF/persistence.xml");
                        Object obj = getClass().getResource("/META-INF/persistence.xml").getContent();
                        System.out.println("-----");
                        System.out.println("CONTENT: " + obj);
                
                
                        String content;
                        DataInputStream dis = new DataInputStream(is);
                        while((content = dis.readLine()) != null) {
                            System.out.println(content);
                        }
                        System.out.println("-----");
                
                
                        Assert.assertNotNull("Entity manager was null.",is);
                        Speaker speaker = new Speaker("name","biography");
                        speakerService.createSpeaker(speaker);
                    }
                }
                
                @Stateless
                @Local
                public class SpeakerService {
                
                
                    /**
                     * Persistence context
                     */
                    @PersistenceContext(name = "ctjug") // added the name="ctjug" during troubleshooting
                    private EntityManager em;
                
                
                    /**
                     * Creates a new speaker
                     * @param speaker - speaker to be created
                     */
                    public void createSpeaker(Speaker speaker) {
                        em.persist(speaker);
                    }
                
                
                    /**
                     * Updates an existing speaker
                     * @param speaker - speaker to be updated
                     */
                    public void updateSpeaker(Speaker speaker) {
                        em.merge(speaker);
                    }
                
                
                    /**
                     * Returns a list of speakers
                     * @return speakers
                     */
                    public List<Speaker> getSpeakers() {
                        return em.createQuery("select s from speaker s").getResultList();
                    }
                }
                
                
                
                • 5. Re: Persistence Context is null
                  Aslak Knutsen Master

                  persistence.xml should be under WEB-INF/classes/META-INF

                   

                  addAsResource(Descriptor...., "META-INF/persistence.xml")