The reason i ask for why the context is not being active is, that i wanted to use a transaction scoped EM for my data access methods(query db) too. I want the persistence context to be cleared or closed everytime i leave my "outermost" business or a data access method to prevent lazy loading in a different layer. My problem with the transaction scope is, that i can't use it in the data access methods, since i don't want to open a transaction for ever db access. Shouldn't the transaction scope behave like a persistence context within an ejb? How do you handle that kind of problem? Am 30.10.2012 12:27 schrieb "Christian Beikov" <c.bei...@curecomp.com>:
> Am 30.10.2012 10:58, schrieb Mark Struberg: > >> Hi Christian! >> >> We might need to tweak the docs a bit. using @PersistenceContext for >> injecting an EM will give you a 'container managed EM' if you run that code >> in an EE server like WS8, JBossAS, etc. Those EMs _only_ work together with >> EJBs. >> >> If you need JTA then you can use a PersistenceContextType.**EXTENDED >> EntiryManager and a UserTransaction. Our @TransactionScoped is able to >> handle that. >> >> If you just have a single database and don't like to use JTA, then you >> can simply create the EM yourself inside the producer [1]. Please note that >> you need to add the 'resource-local' to your persistence.xml if you like to >> be 100% spec conform: >> >> <persistence-unit name="yourunit" transaction-type="RESOURCE_**LOCAL">... >> >> >> In our real world application we have an own EntityManagerFactoryProducer >> which not only creates the EntityManagerFactory but also acts as a central >> point for all the configuration. >> > > The extended persistence context will do it hopefully. But by the way, if > I use TransactionScoped for an entity manager and try to use that entity > manager in a method that does not use @Transactional I get an error that > the context is not active, is that expected? > > >> LieGrue, >> strub >> >> >> [1] https://github.com/struberg/**lightweightEE/blob/master/** >> backend/src/main/java/de/**jaxenter/eesummit/caroline/**backend/tools/** >> EntityManagerProducer.java<https://github.com/struberg/lightweightEE/blob/master/backend/src/main/java/de/jaxenter/eesummit/caroline/backend/tools/EntityManagerProducer.java> >> >> >> >> >> ----- Original Message ----- >> >>> From: Christian Beikov <c.bei...@curecomp.com> >>> To: >>> deltaspike-users@incubator.**apache.org<deltaspike-users@incubator.apache.org> >>> Cc: >>> Sent: Tuesday, October 30, 2012 10:28 AM >>> Subject: JPA Module Problem with Websphere 8 >>> >>> 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.**NormalScopedBeanInterceptorHan** >>> dler.getContextualInstance(**NormalScopedBeanInterceptorHan** >>> dler.java:124) >>> at >>> org.apache.webbeans.intercept.**NormalScopedBeanInterceptorHan** >>> dler.invoke(**NormalScopedBeanInterceptorHan**dler.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.** >>> ResourceLocalTransactionStrate**gy.execute(** >>> ResourceLocalTransactionStrate**gy.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.**NormalScopedBeanInterceptorHan** >>> dler.callAroundInvokes(**NormalScopedBeanInterceptorHan**dler.java:110) >>> at >>> org.apache.webbeans.intercept.**InterceptorHandler.invoke(** >>> InterceptorHandler.java:266) >>> at >>> org.apache.webbeans.intercept.**NormalScopedBeanInterceptorHan** >>> dler.invoke(**NormalScopedBeanInterceptorHan**dler.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.**NormalScopedBeanInterceptorHan** >>> dler.getContextualInstance(**NormalScopedBeanInterceptorHan** >>> dler.java:124) >>> at >>> org.apache.webbeans.intercept.**NormalScopedBeanInterceptorHan** >>> dler.invoke(**NormalScopedBeanInterceptorHan**dler.java:95) >>> ... >>> >>> Can anyone help me with that please? >>> >>> Regards, >>> Christian >>> >>> >