6 Replies Latest reply on Aug 2, 2011 5:22 AM by Daniel Wegener

    Jersey + Persistence Module (Seam 3) + EclipseLink

    raid3n Newbie

      Hello, excuse my english (I'm italian). I'm a beginner with the JEE architecture.


      I'm coding rest APIs with the Jersey Library. I use JPA (EclipseLink) to manage entities. I use the servlet container Tomcat 6.0.32 that doesn't support the EntityManager injection.
      So I read that Persistence Module (Seam 3) could resolve that issue.


      So I downloaded seam-persistence-3.0.zip  and I put into my classpath library seam-persistence.jar and seam-solder.jar. Then I created beans.xml with the interceptor as written in the reference guide and I put it into my WEB-INF directory. I haven't seam2 into my classpath.


      Is it possible to manage (with the @SeamManaged annotaion) jersey services? Do I need other libraries?


      I would like something:




      @Path("/hello")
      public class HelloService {
      
              @SeamManaged     
              @PersistenceUnit(uniName="PU");  
              EntityManagerFactory emf;
      
              @Inject EntityManager entityManager
      }





      Thank you.

        • 1. Re: Jersey + Persistence Module (Seam 3) + EclipseLink
          raid3n Newbie

          Getting some errors...


          I have into WEB-INF/lib these libraries:
          seam-solder.jar
          persistence.jar
          weld-servlet.jar
          and jersey libraries


          My web.xml:



          <?xml version="1.0" encoding="UTF-8"?>
          <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
               xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
               id="WebApp_ID" version="2.5">
               <display-name>Prova3</display-name>
               <welcome-file-list>
                    <welcome-file>index.html</welcome-file>
                    <welcome-file>index.htm</welcome-file>
                    <welcome-file>index.jsp</welcome-file>
                    <welcome-file>default.html</welcome-file>
                    <welcome-file>default.htm</welcome-file>
                    <welcome-file>default.jsp</welcome-file>
               </welcome-file-list>
               <listener>
                    <listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
               </listener>
               <servlet>
                    <description>JAX-RS Tools Generated - Do not modify</description>
                    <servlet-name>JAX-RS Servlet</servlet-name>
                    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
                    <init-param>
                         <param-name>com.sun.jersey.config.property.packages</param-name>
                         <param-value>service</param-value>
                    </init-param>
                    <load-on-startup>1</load-on-startup>
               </servlet>
               <servlet-mapping>
                    <servlet-name>JAX-RS Servlet</servlet-name>
                    <url-pattern>/*</url-pattern>
               </servlet-mapping>
          
               <resource-env-ref>
                    <resource-env-ref-name>BeanManager</resource-env-ref-name>
                    <resource-env-ref-type>javax.enterprise.inject.spi.BeanManager</resource-env-ref-type>
               </resource-env-ref>
          </web-app>



          My context.xml



          <?xml version="1.0" encoding="UTF-8"?>
          <Context>
               <Resource name="BeanManager" auth="Container"
                    type="javax.enterprise.inject.spi.BeanManager" factory="org.jboss.weld.resources.ManagerObjectFactory" />
          <Listener 
          className="org.jboss.weld.environment.tomcat.WeldLifecycleListener" />
          </Context>




          And the errors I have:




          9-mar-2011 10.27.42 org.apache.catalina.core.AprLifecycleListener init
          INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.6.0_23\bin;.;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\
          9-mar-2011 10.27.42 org.apache.tomcat.util.digester.SetPropertiesRule begin
          AVVERTENZA: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:Prova3' did not find a matching property.
          9-mar-2011 10.27.43 org.apache.coyote.http11.Http11Protocol init
          INFO: Initializing Coyote HTTP/1.1 on http-8080
          9-mar-2011 10.27.43 org.apache.catalina.startup.Catalina load
          INFO: Initialization processed in 926 ms
          9-mar-2011 10.27.43 org.apache.catalina.core.StandardService start
          INFO: Starting service Catalina
          9-mar-2011 10.27.43 org.apache.catalina.core.StandardEngine start
          INFO: Starting Servlet Engine: Apache Tomcat/6.0.32
          9-mar-2011 10.27.44 org.jboss.weld.bootstrap.WeldBootstrap <clinit>
          INFO: WELD-000900 1.1.0 (Final)
          9-mar-2011 10.27.44 org.jboss.weld.bootstrap.WeldBootstrap startContainer
          INFO: WELD-000101 Transactional services not available. Injection of @Inject UserTransaction not available. Transactional observers will be invoked synchronously.
          9-mar-2011 10.27.44 org.jboss.seam.solder.core.CoreExtension beforeBeanDiscovery
          INFO: Seam Solder 3.0.0.CR1 (build id: 3.0.0.CR1)
          9-mar-2011 10.27.44 org.jboss.weld.environment.servlet.Listener contextInitialized
          INFO: Tomcat 6 detected, CDI injection will be available in Servlets and Filters. Injection into Listeners is not supported
          9-mar-2011 10.27.45 org.jboss.seam.solder.core.CoreExtension processAnnotatedType
          INFO: Preventing class org.jboss.seam.persistence.hibernate.HibernateManagedSessionExtensionImpl from being installed as bean due to @Veto annotation
          9-mar-2011 10.27.45 org.apache.catalina.core.StandardContext listenerStart
          GRAVE: Exception sending context initialized event to listener instance of class org.jboss.weld.environment.servlet.Listener
          com.google.common.collect.ComputationException: org.jboss.weld.resources.spi.ResourceLoadingException: Error loading class org.jboss.seam.persistence.transaction.Work
               at com.google.common.collect.ComputingConcurrentHashMap.compute(ComputingConcurrentHashMap.java:218)
               at com.google.common.collect.ComputingConcurrentHashMap.apply(ComputingConcurrentHashMap.java:100)
               at com.google.common.collect.MapMaker$ComputingMapAdapter.get(MapMaker.java:515)
               at org.jboss.weld.resources.ClassTransformer.loadClass(ClassTransformer.java:183)
               at org.jboss.weld.bootstrap.BeanDeployer.addClass(BeanDeployer.java:96)
               at org.jboss.weld.bootstrap.BeanDeployer.addClasses(BeanDeployer.java:133)
               at org.jboss.weld.bootstrap.BeanDeployment.deployBeans(BeanDeployment.java:192)
               at org.jboss.weld.bootstrap.WeldBootstrap.deployBeans(WeldBootstrap.java:364)
               at org.jboss.weld.environment.servlet.Listener.contextInitialized(Listener.java:270)
               at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4205)
               at org.apache.catalina.core.StandardContext.start(StandardContext.java:4704)
               at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
               at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
               at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
               at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
               at org.apache.catalina.core.StandardService.start(StandardService.java:525)
               at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
               at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
               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.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
               at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
          Caused by: org.jboss.weld.resources.spi.ResourceLoadingException: Error loading class org.jboss.seam.persistence.transaction.Work
               at org.jboss.weld.resources.ClassTransformer.loadClass(ClassTransformer.java:189)
               at org.jboss.weld.introspector.jlr.WeldClassImpl.<init>(WeldClassImpl.java:146)
               at org.jboss.weld.introspector.jlr.WeldClassImpl.of(WeldClassImpl.java:124)
               at org.jboss.weld.resources.ClassTransformer$TransformTypeToWeldClass.apply(ClassTransformer.java:54)
               at org.jboss.weld.resources.ClassTransformer$TransformTypeToWeldClass.apply(ClassTransformer.java:42)
               at com.google.common.collect.ComputingConcurrentHashMap.compute(ComputingConcurrentHashMap.java:206)
               ... 23 more
          Caused by: java.lang.NoClassDefFoundError: javax/transaction/UserTransaction
               at java.lang.ClassLoader.defineClass1(Native Method)
               at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
               at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
               at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
               at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2818)
               at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1159)
               at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1647)
               at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
               at java.lang.Class.getDeclaredMethods0(Native Method)
               at java.lang.Class.privateGetDeclaredMethods(Class.java:2427)
               at java.lang.Class.getDeclaredMethods(Class.java:1791)
               at org.jboss.weld.util.reflection.SecureReflections$8.work(SecureReflections.java:198)
               at org.jboss.weld.util.reflection.SecureReflections$8.work(SecureReflections.java:194)
               at org.jboss.weld.util.reflection.SecureReflectionAccess.run(SecureReflectionAccess.java:54)
               at org.jboss.weld.util.reflection.SecureReflectionAccess.runAndWrap(SecureReflectionAccess.java:67)
               at org.jboss.weld.util.reflection.SecureReflections.getDeclaredMethods(SecureReflections.java:193)
               at org.jboss.weld.introspector.jlr.WeldClassImpl.<init>(WeldClassImpl.java:262)
               at org.jboss.weld.introspector.jlr.WeldClassImpl.of(WeldClassImpl.java:124)
               at org.jboss.weld.resources.ClassTransformer$TransformTypeToWeldClass.apply(ClassTransformer.java:54)
               at org.jboss.weld.resources.ClassTransformer$TransformTypeToWeldClass.apply(ClassTransformer.java:42)
               at com.google.common.collect.ComputingConcurrentHashMap.compute(ComputingConcurrentHashMap.java:206)
               at com.google.common.collect.ComputingConcurrentHashMap.apply(ComputingConcurrentHashMap.java:100)
               at com.google.common.collect.MapMaker$ComputingMapAdapter.get(MapMaker.java:515)
               at org.jboss.weld.resources.ClassTransformer.loadClass(ClassTransformer.java:183)
               ... 28 more
          Caused by: java.lang.ClassNotFoundException: javax.transaction.UserTransaction
               at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
               at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
               ... 52 more
          9-mar-2011 10.27.45 org.apache.catalina.core.StandardContext start
          GRAVE: Error listenerStart
          9-mar-2011 10.27.45 org.apache.catalina.core.StandardContext start
          GRAVE: Context [/Prova3] startup failed due to previous errors
          9-mar-2011 10.27.45 org.apache.coyote.http11.Http11Protocol start
          INFO: Starting Coyote HTTP/1.1 on http-8080
          9-mar-2011 10.27.46 org.apache.jk.common.ChannelSocket init
          INFO: JK: ajp13 listening on /0.0.0.0:8009
          9-mar-2011 10.27.46 org.apache.jk.server.JkMain start
          INFO: Jk running ID=0 time=0/24  config=null
          9-mar-2011 10.27.46 org.apache.catalina.startup.Catalina start
          INFO: Server startup in 2670 ms



          Suggestions?

          • 2. Re: Jersey + Persistence Module (Seam 3) + EclipseLink
            Jason Porter Master

            Andrea de Ruvo wrote on Mar 09, 2011 04:35:


            Getting some errors...

            ...

            Caused by: java.lang.ClassNotFoundException: javax.transaction.UserTransaction

            Suggestions?



            You'll need the jta jar in your application. You may not use jta, but you need the classes.

            • 3. Re: Jersey + Persistence Module (Seam 3) + EclipseLink
              raid3n Newbie

              Thx Jason, I solved it but now I have other problems. I'm reading the persistence documentation (Persistence Module) and I have written a class:




              @ApplicationScoped
              public class EMProducer {
                      @SeamManaged
                      @Produces
                      @PersistenceUnit(unitName = "pu")
                      @ConversationScoped
                      @Test
                      private EntityManagerFactory emf;
              }





              Now I would inject EntityManager in my Jersey Service:




              @ApplicationScoped
              @Path("/hello")
              public class Hello {
              
                      @Inject
                      @Test
                      @PersistenceContext
                      EntityManager em;
              
                      @GET    
                      @Produces(MediaType.TEXT_PLAIN)
                      public void hello() {
                              em.createQuery("select f from Form f").getResultList().size();          
                      }
              }





              but I get errors:



              GRAVE: The RuntimeException could not be mapped to a response, re-throwing to the HTTP container
              org.jboss.weld.context.ContextNotActiveException: WELD-001303 No active contexts for scope type javax.enterprise.context.ConversationScoped
                      at org.jboss.weld.manager.BeanManagerImpl.getContext(BeanManagerImpl.java:664)
                      at org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:77)
                      at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:124)
                      at org.jboss.weld.proxies.SMPC-org$jboss$seam$persistence$ManagedPersistenceContextExtension-cdi$EMProducer$emf[@javax$enterprise$context$ConversationScoped()@javax$enterprise$inject$Produces()@javax$persistence$PersistenceUnit(name=,unitName=pu)@org$jboss$seam$persistence$SeamManaged()]_$$_WeldClientProxy.createQuery(SMPC-org$jboss$seam$persistence$ManagedPersistenceContextExtension-cdi$EMProducer$emf[@javax$enterprise$context$ConversationScoped()@javax$enterprise$inject$Produces()@javax$persistence$PersistenceUnit(name=,unitName=pu)@org$jboss$seam$persistence$SeamManaged()]_$$_WeldClientProxy.java)
                      at service.Hello.hello(Hello.java:44)
                      at service.org$jboss$weld$bean-flat-ManagedBean-class_service$Hello_$$_WeldClientProxy.hello(org$jboss$weld$bean-flat-ManagedBean-class_service$Hello_$$_WeldClientProxy.java)
                      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.jersey.server.impl.model.method.dispatch.VoidVoidDispatchProvider$VoidVoidMethodInvoker._dispatch(VoidVoidDispatchProvider.java:63)
                      at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:70)
                      at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:279)
                      at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:136)
                      at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:86)
                      at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:136)
                      at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:74)
                      at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1347)
                      at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1279)
                      at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1229)
                      at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1219)
                      at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:419)
                      at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
                      at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699)
                      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
                      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
                      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
                      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
                      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
                      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
                      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
                      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
                      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
                      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
                      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
                      at java.lang.Thread.run(Thread.java:662)
              9-mar-2011 16.09.30 org.apache.catalina.core.StandardWrapperValve invoke
              GRAVE: Servlet.service() for servlet JAX-RS Servlet threw exception
              org.jboss.weld.context.ContextNotActiveException: WELD-001303 No active contexts for scope type javax.enterprise.context.ConversationScoped
                      at org.jboss.weld.manager.BeanManagerImpl.getContext(BeanManagerImpl.java:664)
                      at org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:77)
                      at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:124)
                      at org.jboss.weld.proxies.SMPC-org$jboss$seam$persistence$ManagedPersistenceContextExtension-cdi$EMProducer$emf[@javax$enterprise$context$ConversationScoped()@javax$enterprise$inject$Produces()@javax$persistence$PersistenceUnit(name=,unitName=pu)@org$jboss$seam$persistence$SeamManaged()]_$$_WeldClientProxy.createQuery(SMPC-org$jboss$seam$persistence$ManagedPersistenceContextExtension-cdi$EMProducer$emf[@javax$enterprise$context$ConversationScoped()@javax$enterprise$inject$Produces()@javax$persistence$PersistenceUnit(name=,unitName=pu)@org$jboss$seam$persistence$SeamManaged()]_$$_WeldClientProxy.java)
                      at service.Hello.hello(Hello.java:44)
                      at service.org$jboss$weld$bean-flat-ManagedBean-class_service$Hello_$$_WeldClientProxy.hello(org$jboss$weld$bean-flat-ManagedBean-class_service$Hello_$$_WeldClientProxy.java)
                      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.jersey.server.impl.model.method.dispatch.VoidVoidDispatchProvider$VoidVoidMethodInvoker._dispatch(VoidVoidDispatchProvider.java:63)
                      at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:70)
                      at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:279)
                      at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:136)
                      at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:86)
                      at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:136)
                      at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:74)
                      at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1347)
                      at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1279)
                      at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1229)
                      at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1219)
                      at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:419)
                      at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
                      at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699)
                      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
                      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
                      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
                      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
                      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
                      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
                      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
                      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
                      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
                      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
                      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
                      at java.lang.Thread.run(Thread.java:662)



              I'm digging google to solve :(

              • 4. Re: Jersey + Persistence Module (Seam 3) + EclipseLink
                Jason Porter Master

                Yep, I've seen this problem too, the solution I used (and Jozef in the Rest module) is let the EJB container manage the entity manager and create producer for it. Stuart may have a better solution for you though.

                • 5. Re: Jersey + Persistence Module (Seam 3) + EclipseLink
                  raid3n Newbie

                  The problem is that that application should be deployed into tomcat 6 without an ejb container.


                  It seems @ConversationScoped doesn't work fine with Jersey Servlets.


                  I don't know how to solve.


                  Now I'have this Jersey servlet with a seammanaged persistence context that doesn't work.




                  @ApplicationScoped
                  @Path("/hello")
                  public class Hello {
                  
                       @Inject
                       @MyRandom
                       int randomNumber;
                       
                       @CentralRepo
                          @SeamManaged    
                          @ConversationScoped
                          @javax.enterprise.inject.Produces
                          @PersistenceUnit(unitName="pu")
                          EntityManagerFactory centralEmf;
                  
                          @Inject
                       @CentralRepo
                       EntityManager em;
                  
                       @SuppressWarnings("unchecked")
                       @GET
                       @Path("/all")
                       @Produces(MediaType.APPLICATION_XML)
                       public List<Form> getClichedMessage() {
                            List<Form> l = null;          
                            l = em.createQuery("select e from Entity e").getResultList();          
                            return l;
                       }
                  }



                  And this is the stack errors:



                  9-mar-2011 18.09.42 com.sun.jersey.spi.container.ContainerResponse mapMappableContainerException
                  GRAVE: The RuntimeException could not be mapped to a response, re-throwing to the HTTP container
                  org.jboss.weld.context.ContextNotActiveException: WELD-001303 No active contexts for scope type javax.enterprise.context.ConversationScoped
                       at org.jboss.weld.manager.BeanManagerImpl.getContext(BeanManagerImpl.java:664)
                       at org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:77)
                       at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:124)
                       at org.jboss.weld.proxies.SMPC-org$jboss$seam$persistence$ManagedPersistenceContextExtension-service$Hello$centralEmf[@javax$enterprise$context$ConversationScoped()@javax$enterprise$inject$Produces()@javax$persistence$PersistenceUnit(name=persistence$Prova,unitName=pu)@org$jboss$seam$persistence$SeamManaged()]_$$_WeldClientProxy.createQuery(SMPC-org$jboss$seam$persistence$ManagedPersistenceContextExtension-service$Hello$centralEmf[@javax$enterprise$context$ConversationScoped()@javax$enterprise$inject$Produces()@javax$persistence$PersistenceUnit(name=persistence$Prova,unitName=pu)@org$jboss$seam$persistence$SeamManaged()]_$$_WeldClientProxy.java)
                       at service.Hello.getClichedMessage(Hello.java:56)
                       at service.org$jboss$weld$bean-flat-ManagedBean-service$Hello[@javax$enterprise$context$ApplicationScoped()@javax$ws$rs$Path(value=$hello)]{service$Hello$centralEmf[@javax$persistence$PersistenceUnit(name=persistence$Prova,unitName=pu)@org$jboss$seam$persistence$SeamManaged()]$service$Hello$em[@javax$inject$Inject()]$service$Hello$randomNumber[@javax$inject$Inject()]$service$Hello$getClichedMessage[@javax$ws$rs$GET()@javax$ws$rs$Path(value=$all)@javax$ws$rs$Produces(value=[Ljava$lang$String$@672bb3)]()$service$Hello$hello[@javax$ws$rs$GET()@javax$ws$rs$Path(value=$hello)@javax$ws$rs$Produces(value=[Ljava$lang$String$@1662429)]()$}_$$_WeldClientProxy.getClichedMessage(org$jboss$weld$bean-flat-ManagedBean-service$Hello[@javax$enterprise$context$ApplicationScoped()@javax$ws$rs$Path(value=$hello)]{service$Hello$centralEmf[@javax$persistence$PersistenceUnit(name=persistence$Prova,unitName=pu)@org$jboss$seam$persistence$SeamManaged()]$service$Hello$em[@javax$inject$Inject()]$service$Hello$randomNumber[@javax$inject$Inject()]$service$Hello$getClichedMessage[@javax$ws$rs$GET()@javax$ws$rs$Path(value=$all)@javax$ws$rs$Produces(value=[Ljava$lang$String$@672bb3)]()$service$Hello$hello[@javax$ws$rs$GET()@javax$ws$rs$Path(value=$hello)@javax$ws$rs$Produces(value=[Ljava$lang$String$@1662429)]()$}_$$_WeldClientProxy.java)
                       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.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:167)
                       at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:70)
                       at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:279)
                       at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:136)
                       at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:86)
                       at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:136)
                       at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:74)
                       at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1347)
                       at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1279)
                       at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1229)
                       at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1219)
                       at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:419)
                       at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
                       at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699)
                       at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
                       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
                       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
                       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
                       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
                       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
                       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
                       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
                       at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
                       at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
                       at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
                       at java.lang.Thread.run(Thread.java:662)
                  9-mar-2011 18.09.42 org.apache.catalina.core.StandardWrapperValve invoke
                  GRAVE: Servlet.service() for servlet JAX-RS Servlet threw exception
                  org.jboss.weld.context.ContextNotActiveException: WELD-001303 No active contexts for scope type javax.enterprise.context.ConversationScoped
                       at org.jboss.weld.manager.BeanManagerImpl.getContext(BeanManagerImpl.java:664)
                       at org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:77)
                       at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:124)
                       at org.jboss.weld.proxies.SMPC-org$jboss$seam$persistence$ManagedPersistenceContextExtension-service$Hello$centralEmf[@javax$enterprise$context$ConversationScoped()@javax$enterprise$inject$Produces()@javax$persistence$PersistenceUnit(name=persistence$Prova,unitName=pu)@org$jboss$seam$persistence$SeamManaged()]_$$_WeldClientProxy.createQuery(SMPC-org$jboss$seam$persistence$ManagedPersistenceContextExtension-service$Hello$centralEmf[@javax$enterprise$context$ConversationScoped()@javax$enterprise$inject$Produces()@javax$persistence$PersistenceUnit(name=persistence$Prova,unitName=pu)@org$jboss$seam$persistence$SeamManaged()]_$$_WeldClientProxy.java)
                       at service.Hello.getClichedMessage(Hello.java:56)
                       at service.org$jboss$weld$bean-flat-ManagedBean-service$Hello[@javax$enterprise$context$ApplicationScoped()@javax$ws$rs$Path(value=$hello)]{service$Hello$centralEmf[@javax$persistence$PersistenceUnit(name=persistence$Prova,unitName=pu)@org$jboss$seam$persistence$SeamManaged()]$service$Hello$em[@javax$inject$Inject()]$service$Hello$randomNumber[@javax$inject$Inject()]$service$Hello$getClichedMessage[@javax$ws$rs$GET()@javax$ws$rs$Path(value=$all)@javax$ws$rs$Produces(value=[Ljava$lang$String$@672bb3)]()$service$Hello$hello[@javax$ws$rs$GET()@javax$ws$rs$Path(value=$hello)@javax$ws$rs$Produces(value=[Ljava$lang$String$@1662429)]()$}_$$_WeldClientProxy.getClichedMessage(org$jboss$weld$bean-flat-ManagedBean-service$Hello[@javax$enterprise$context$ApplicationScoped()@javax$ws$rs$Path(value=$hello)]{service$Hello$centralEmf[@javax$persistence$PersistenceUnit(name=persistence$Prova,unitName=pu)@org$jboss$seam$persistence$SeamManaged()]$service$Hello$em[@javax$inject$Inject()]$service$Hello$randomNumber[@javax$inject$Inject()]$service$Hello$getClichedMessage[@javax$ws$rs$GET()@javax$ws$rs$Path(value=$all)@javax$ws$rs$Produces(value=[Ljava$lang$String$@672bb3)]()$service$Hello$hello[@javax$ws$rs$GET()@javax$ws$rs$Path(value=$hello)@javax$ws$rs$Produces(value=[Ljava$lang$String$@1662429)]()$}_$$_WeldClientProxy.java)
                       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.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:167)
                       at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:70)
                       at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:279)
                       at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:136)
                       at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:86)
                       at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:136)
                       at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:74)
                       at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1347)
                       at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1279)
                       at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1229)
                       at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1219)
                       at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:419)
                       at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
                       at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699)
                       at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
                       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
                       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
                       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
                       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
                       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
                       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
                       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
                       at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
                       at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
                       at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
                       at java.lang.Thread.run(Thread.java:662)




                  I hope someone has the solution.

                  • 6. Re: Jersey + Persistence Module (Seam 3) + EclipseLink
                    Daniel Wegener Newbie

                    Guess this one is easy. Just change your EMF-producer-field for the seam managed persistence context


                    @CentralRepo
                    @SeamManaged    
                    @ConversationScoped
                    @javax.enterprise.inject.Produces
                    @PersistenceUnit(unitName="pu")
                    EntityManagerFactory centralEmf;



                    to the request scope (if you dont use conversations anyway)


                    @CentralRepo
                    @SeamManaged    
                    @RequestScoped
                    @javax.enterprise.inject.Produces
                    @PersistenceUnit(unitName="pu")
                    EntityManagerFactory centralEmf;



                    This at least worked for me getting seam persistence running with vaadin.