Hey guys!

I tried to use the JPA Module today within Websphere 8 and faced a problem.
I have a class that produces an entity manager as described in the documentation and I am using the transaction scope like the following:


    @PersistenceContext(
            unitName = "ClevercureNew")
    private EntityManager em;

    @Produces
    @TransactionScoped
    protected EntityManager createEntityManager(){
        return em;
    }

    protected void closeEntityManager(@Disposes EntityManager em){
        if(em.isOpen()){
            em.close();
        }
    }

When I start the application I fire a CDI Event to some observers, that my application has been started. Some of these observers use JPA to persist some things and therefore I use the Transactional interceptor. Unfortunately I receive an error from the transactional interceptor:

[30.10.12 10:22:37:723 CET] 0000001c webapp E com.ibm.ws.webcontainer.webapp.WebApp notifyServletContextCreated SRVE0283E: Exception caught while initializing context: {0} javax.enterprise.context.ContextNotActiveException: WebBeans context with scope type annotation @RequestScoped does not exist within current thread at org.apache.webbeans.container.BeanManagerImpl.getContext(BeanManagerImpl.java:321) at org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler.getContextualInstance(NormalScopedBeanInterceptorHandler.java:124) at org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler.invoke(NormalScopedBeanInterceptorHandler.java:95) at org.apache.deltaspike.jpa.impl.transaction.context.TransactionBeanStorage_$$_javassist_370.isEmpty(TransactionBeanStorage_$$_javassist_370.java) at org.apache.deltaspike.jpa.impl.transaction.ResourceLocalTransactionStrategy.execute(ResourceLocalTransactionStrategy.java:82) at org.apache.deltaspike.jpa.impl.transaction.TransactionalInterceptor.executeInTransaction(TransactionalInterceptor.java:57)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
    at java.lang.reflect.Method.invoke(Method.java:611)
at org.apache.webbeans.intercept.InvocationContextImpl.proceedAroundInvokes(InvocationContextImpl.java:237) at org.apache.webbeans.intercept.InvocationContextImpl.proceed(InvocationContextImpl.java:175) at org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler.callAroundInvokes(NormalScopedBeanInterceptorHandler.java:110) at org.apache.webbeans.intercept.InterceptorHandler.invoke(InterceptorHandler.java:266) at org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler.invoke(NormalScopedBeanInterceptorHandler.java:98) at com.clevercure.dm.service.impl.DocumentServiceImpl_$$_javassist_367.setupData(DocumentServiceImpl_$$_javassist_367.java) at com.clevercure.dm.service.event.handler.StartupObserver.observe(StartupObserver.java:27)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
    at java.lang.reflect.Method.invoke(Method.java:611)
at org.apache.webbeans.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:285) at org.apache.webbeans.event.NotificationManager.fireEvent(NotificationManager.java:455) at org.apache.webbeans.container.BeanManagerImpl.fireEvent(BeanManagerImpl.java:415)
    at org.apache.webbeans.event.EventImpl.fire(EventImpl.java:76)
at com.clevercure.collab.service.event.handler.StartupObserver.observe(StartupObserver.java:29)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
    at java.lang.reflect.Method.invoke(Method.java:611)
at org.apache.webbeans.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:285) at org.apache.webbeans.event.NotificationManager.fireEvent(NotificationManager.java:455) at org.apache.webbeans.container.BeanManagerImpl.fireEvent(BeanManagerImpl.java:415)
    at org.apache.webbeans.event.EventImpl.fire(EventImpl.java:76)
at com.clevercure.core.event.handler.StartupObserver.observe(StartupObserver.java:29)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
    at java.lang.reflect.Method.invoke(Method.java:611)
at org.apache.webbeans.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:285) at org.apache.webbeans.event.NotificationManager.fireEvent(NotificationManager.java:455) at org.apache.webbeans.container.BeanManagerImpl.fireEvent(BeanManagerImpl.java:415)
    at org.apache.webbeans.event.EventImpl.fire(EventImpl.java:76)
at com.clevercure.web.core.application.listener.ApplicationStartupListener.contextInitialized(ApplicationStartupListener.java:33) at com.ibm.ws.webcontainer.webapp.WebApp.notifyServletContextCreated(WebApp.java:1651) at com.ibm.ws.webcontainer.webapp.WebAppImpl.initialize(WebAppImpl.java:410) at com.ibm.ws.webcontainer.webapp.WebGroupImpl.addWebApplication(WebGroupImpl.java:88) at com.ibm.ws.webcontainer.VirtualHostImpl.addWebApplication(VirtualHostImpl.java:169) at com.ibm.ws.webcontainer.WSWebContainer.addWebApp(WSWebContainer.java:745) at com.ibm.ws.webcontainer.WSWebContainer.addWebApplication(WSWebContainer.java:633) at com.ibm.ws.webcontainer.component.WebContainerImpl.install(WebContainerImpl.java:422) at com.ibm.ws.webcontainer.component.WebContainerImpl.start(WebContainerImpl.java:714) at com.ibm.ws.runtime.component.ApplicationMgrImpl.start(ApplicationMgrImpl.java:1138) at com.ibm.ws.runtime.component.DeployedApplicationImpl.fireDeployedObjectStart(DeployedApplicationImpl.java:1369) at com.ibm.ws.runtime.component.DeployedModuleImpl.start(DeployedModuleImpl.java:638) at com.ibm.ws.runtime.component.DeployedApplicationImpl.start(DeployedApplicationImpl.java:967) at com.ibm.ws.runtime.component.ApplicationMgrImpl.startApplication(ApplicationMgrImpl.java:744) at com.ibm.ws.runtime.component.ApplicationMgrImpl.startApplicationDynamically(ApplicationMgrImpl.java:1332) at com.ibm.ws.runtime.component.ApplicationMgrImpl.start(ApplicationMgrImpl.java:2128) at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.start(CompositionUnitMgrImpl.java:445) at com.ibm.ws.runtime.component.CompositionUnitImpl.start(CompositionUnitImpl.java:123) at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.start(CompositionUnitMgrImpl.java:388) at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.access$500(CompositionUnitMgrImpl.java:116) at com.ibm.ws.runtime.component.CompositionUnitMgrImpl$1.run(CompositionUnitMgrImpl.java:663) at com.ibm.ws.security.auth.ContextManagerImpl.runAs(ContextManagerImpl.java:5315) at com.ibm.ws.security.auth.ContextManagerImpl.runAsSystem(ContextManagerImpl.java:5531) at com.ibm.ws.security.core.SecurityContext.runAsSystem(SecurityContext.java:255) at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.startCompositionUnit(CompositionUnitMgrImpl.java:677) at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.startCompositionUnit(CompositionUnitMgrImpl.java:621) at com.ibm.ws.runtime.component.ApplicationMgrImpl.startApplication(ApplicationMgrImpl.java:1224)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
    at java.lang.reflect.Method.invoke(Method.java:611)
    at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:49)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
    at java.lang.reflect.Method.invoke(Method.java:611)
    at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:256)
at javax.management.modelmbean.RequiredModelMBean.invokeMethod(RequiredModelMBean.java:1085) at javax.management.modelmbean.RequiredModelMBean.invoke(RequiredModelMBean.java:966) at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:848) at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:773) at com.ibm.ws.management.AdminServiceImpl$1.run(AdminServiceImpl.java:1335) at com.ibm.ws.security.util.AccessController.doPrivileged(AccessController.java:118) at com.ibm.ws.management.AdminServiceImpl.invoke(AdminServiceImpl.java:1228) at com.ibm.ws.management.application.AppManagementImpl._startApplication(AppManagementImpl.java:1433) at com.ibm.ws.management.application.AppManagementImpl.startApplication(AppManagementImpl.java:1322) at com.ibm.ws.management.application.AppManagementImpl.startApplication(AppManagementImpl.java:1271)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
    at java.lang.reflect.Method.invoke(Method.java:611)
    at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:49)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
    at java.lang.reflect.Method.invoke(Method.java:611)
    at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:256)
at javax.management.modelmbean.RequiredModelMBean.invokeMethod(RequiredModelMBean.java:1085) at javax.management.modelmbean.RequiredModelMBean.invoke(RequiredModelMBean.java:966) at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:848) at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:773) at com.ibm.ws.management.AdminServiceImpl$1.run(AdminServiceImpl.java:1335) at com.ibm.ws.security.util.AccessController.doPrivileged(AccessController.java:118) at com.ibm.ws.management.AdminServiceImpl.invoke(AdminServiceImpl.java:1228) at com.ibm.ws.management.connector.AdminServiceDelegator.invoke(AdminServiceDelegator.java:181) at com.ibm.ws.management.connector.ipc.CallRouter.route(CallRouter.java:247) at com.ibm.ws.management.connector.ipc.IPCConnectorInboundLink.doWork(IPCConnectorInboundLink.java:353) at com.ibm.ws.management.connector.ipc.IPCConnectorInboundLink$IPCConnectorReadCallback.complete(IPCConnectorInboundLink.java:595) at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165) at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217) at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
    at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
    at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
    at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
    at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1650)

Besides this error at application startup, I can see that the resource local transaction strategy is used as default. Shouldn't the default be the environment aware strategy or have I missed to configure something?

The last problem occurs at the "normal" usage scenario where I just try to query something with the entity manager.

Caused by: javax.enterprise.context.ContextNotActiveException: WebBeans context with scope type annotation @TransactionScoped does not exist within current thread at org.apache.webbeans.container.BeanManagerImpl.getContext(BeanManagerImpl.java:321) at org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler.getContextualInstance(NormalScopedBeanInterceptorHandler.java:124) at org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler.invoke(NormalScopedBeanInterceptorHandler.java:95)
...

Can anyone help me with that please?

Regards,
Christian

Reply via email to