5 Replies Latest reply on Jun 5, 2008 3:16 PM by Manuel Martín

    Seam-managed persistence context with JPA

    Manuel Martín Newbie

      Are there any method to get seam managed persistence contexts without adding the property jboss.entity.manager.factory.jndi.name to the file persistence.xml?


      The application is going to be deployed at JBoss AS 4.2.2.GA.


      Thanks a lot!


       

        • 1. Re: Seam-managed persistence context with JPA
          Joshua Jackson Master

          jboss.entity.manager.factory.jndi.name is used if you want to expose your persistence unit to JNDI. Don't use it if you don't want to expose it to JNDI.


          cheers,

          • 2. Re: Seam-managed persistence context with JPA
            Manuel Martín Newbie

            Hi,


            I thought that jboss.entity.manager.factory.jndi.name was required in order to be catched in components.xml by the tag persistence:managed-persistence-context with the attribute persistence-unit-jndi-name and make the persistence context managed by Seam... :-/


            So, if I don't use it I could use @In in PersistenceContext?


            Thanks

            • 3. Re: Seam-managed persistence context with JPA
              infinity2heaven Novice

              I use Seam managed Persisten Context and I refer jndi contexts in both the places


              persistence.xml


              <property name="jboss.entity.manager.factory.jndi.name"  
                 value="java:/EntityManagerFactories/myDatasource"/>
                   


              components.xml


              <persistence:managed-persistence-context name="entityManager" 
                 persistence-unit-jndi
                 name="java:/EntityManagerFactories/myDatasource" />
                    



              I dont think you can avoid this.

              • 4. Re: Seam-managed persistence context with JPA
                Manuel Martín Newbie

                Yes, I think so.


                I tried in components.xml with


                <persistence:entity-manager-factory name="intranet-commons-emf" persistence-unit-name="intranet-commons-pu" auto-create="true" />
                <persistence:managed-persistence-context name="iem"  entity-manager-factory="intranet-commons-emf" auto-create="true" />
                



                in order to try to create a managed persistence context without JNDI btu without success. I obtain the next exception:


                java.lang.RuntimeException: Could not create Component: iem
                     at org.jboss.seam.init.Initialization.addComponent(Initialization.java:989)
                     at org.jboss.seam.init.Initialization.installComponents(Initialization.java:911)
                     at org.jboss.seam.init.Initialization.init(Initialization.java:589)
                     at org.jboss.seam.servlet.SeamListener.contextInitialized(SeamListener.java:34)
                     at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3856)
                     at org.apache.catalina.core.StandardContext.start(StandardContext.java:4361)
                     at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:790)
                     at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:770)
                     at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:553)
                     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
                     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
                     at java.lang.reflect.Method.invoke(Unknown Source)
                     at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:296)
                     at org.jboss.mx.server.RawDynamicInvoker.invoke(RawDynamicInvoker.java:164)
                     at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
                     at org.apache.catalina.core.StandardContext.init(StandardContext.java:5312)
                     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
                     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
                     at java.lang.reflect.Method.invoke(Unknown Source)
                     at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:296)
                     at org.jboss.mx.server.RawDynamicInvoker.invoke(RawDynamicInvoker.java:164)
                     at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
                     at org.jboss.web.tomcat.service.TomcatDeployer.performDeployInternal(TomcatDeployer.java:301)
                     at org.jboss.web.tomcat.service.TomcatDeployer.performDeploy(TomcatDeployer.java:104)
                     at org.jboss.web.AbstractWebDeployer.start(AbstractWebDeployer.java:375)
                     at org.jboss.web.WebModule.startModule(WebModule.java:83)
                     at org.jboss.web.WebModule.startService(WebModule.java:61)
                     at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
                     at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:245)
                     at sun.reflect.GeneratedMethodAccessor161.invoke(Unknown Source)
                     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
                     at java.lang.reflect.Method.invoke(Unknown Source)
                     at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
                     at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
                     at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
                     at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
                     at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
                     at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:978)
                     at $Proxy0.start(Unknown Source)
                     at org.jboss.system.ServiceController.start(ServiceController.java:417)
                     at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
                     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
                     at java.lang.reflect.Method.invoke(Unknown Source)
                     at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
                     at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
                     at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
                     at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
                     at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
                     at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
                     at $Proxy44.start(Unknown Source)
                     at org.jboss.web.AbstractWebContainer.start(AbstractWebContainer.java:466)
                     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
                     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
                     at java.lang.reflect.Method.invoke(Unknown Source)
                     at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
                     at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
                     at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
                     at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
                     at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
                     at org.jboss.mx.interceptor.DynamicInterceptor.invoke(DynamicInterceptor.java:97)
                     at org.jboss.system.InterceptorServiceMBeanSupport.invokeNext(InterceptorServiceMBeanSupport.java:238)
                     at org.jboss.wsf.container.jboss42.DeployerInterceptor.start(DeployerInterceptor.java:87)
                     at org.jboss.deployment.SubDeployerInterceptorSupport$XMBeanInterceptor.start(SubDeployerInterceptorSupport.java:188)
                     at org.jboss.deployment.SubDeployerInterceptor.invoke(SubDeployerInterceptor.java:95)
                     at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
                     at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
                     at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
                     at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
                     at $Proxy45.start(Unknown Source)
                     at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1025)
                     at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1015)
                     at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:819)
                     at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:782)
                     at sun.reflect.GeneratedMethodAccessor20.invoke(Unknown Source)
                     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
                     at java.lang.reflect.Method.invoke(Unknown Source)
                     at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
                     at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
                     at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
                     at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
                     at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
                     at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
                     at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
                     at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
                     at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
                     at $Proxy9.deploy(Unknown Source)
                     at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:421)
                     at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:610)
                     at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.doScan(AbstractDeploymentScanner.java:263)
                     at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.loop(AbstractDeploymentScanner.java:274)
                     at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.run(AbstractDeploymentScanner.java:225)
                Caused by: java.lang.IllegalArgumentException: No converter for type: org.jboss.seam.core.Expressions$ValueExpression
                     at org.jboss.seam.util.Conversions.getConverter(Conversions.java:61)
                     at org.jboss.seam.Component$ConstantInitialValue.<init>(Component.java:2320)
                     at org.jboss.seam.Component.getInitialValue(Component.java:518)
                     at org.jboss.seam.Component.getTopInitialValue(Component.java:498)
                     at org.jboss.seam.Component.initInitializers(Component.java:476)
                     at org.jboss.seam.Component.<init>(Component.java:264)
                     at org.jboss.seam.Component.<init>(Component.java:217)
                     at org.jboss.seam.init.Initialization.addComponent(Initialization.java:974)
                     ... 93 more
                



                If I must use JNDI then... what happens if two applications share the same JNDI entity manager name? the application crash on deploy?


                Thanks!

                • 5. Re: Seam-managed persistence context with JPA
                  Manuel Martín Newbie

                  I get a mistake in last post. I tried with


                  <persistence:entity-manager-factory name="intranet-commons-emf" persistence-unit-name="intranet-commons-pu" auto-create="true" />
                  <persistence:managed-persistence-context name="iem"  entity-manager-factory="#{intranet-commons-emf}" auto-create="true" />
                  



                  but still without success.


                  The problem is that I want to make a JAR with some entities, EJB3 and seam components. All packaged with its own persistence.xml.


                  The problem is not the declaration in components.xml which could depends of each application. The problem is with persistence.xml of the JAR library. If I add jboss.entity.manager.factory.jndi.name all applications that uses the library are going to try to put in the seam JNDI name their persistence unit.


                  Any idea to workarround this?


                  Thanks!