5 Replies Latest reply on May 19, 2010 7:50 AM by shane lee

    EntityManagerFactory not found in JNDI (project created by seam-gen)

    slawek t Novice

      I've created project myproject using seam-gen from Seam 2.2.0.GA and during development in eclipse it's deployed as EAR (exploaded: myproject.ear) in JBoss 5.1.0.GA.


      I didn't change anything in configuration files except adding


      <factory name="session" method="#{entityManager.getDelegate( )}"
                      scope="STATELESS" auto-create="true" />
      


      to WEB-INF/components.xml


      When i'm adding

      #{someAction.getUserNameByLogin('login1')}

      to generated by seam-gen /home.xhtml  an exception raises:
      javax.el.ELException: /home.xhtml: javax.ejb.EJBTransactionRolledbackException: EntityManagerFactory not found in JNDI : java:comp/env/myproject/pu
      


      (full stack trace below)





      my action is:


      ...
          public String getUserNameByLogin( String login ) {
              User u = ( User ) session.createQuery( "from User u where u.login = :login ).setParameter( "login", login ).uniqueResult( );
              return u != null ? u.getName( ) : null;
          }
      ...



      It's not working out of the box, so please advise how to fix the issue with EntityManagerFactory configuration.








      Full stack trace:


      21:25:30,526 ERROR [TxPolicy] javax.ejb.EJBTransactionRolledbackException: EntityManagerFactory not found in JNDI : java:comp/env/myproject/pu
      21:25:30,527 SEVERE [viewhandler] Error Rendering View[/home.xhtml]
      javax.el.ELException: /home.xhtml: javax.ejb.EJBTransactionRolledbackException: EntityManagerFactory not found in JNDI : java:comp/env/myproject/pu
              at com.sun.facelets.compiler.TextInstruction.write(TextInstruction.java:48)
              at com.sun.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:39)
              at com.sun.facelets.compiler.UILeaf.encodeAll(UILeaf.java:149)
              at javax.faces.component.UIComponent.encodeAll(UIComponent.java:933)
              at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:592)
              at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:100)
              at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:176)
              at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:110)
              at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
              at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
              at javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
              at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
              at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
              at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:368)
              at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:495)
              at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:60)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.web.HotDeployFilter.doFilter(HotDeployFilter.java:53)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
              at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
              at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
              at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
              at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
              at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
              at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
              at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
              at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
              at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
              at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
              at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
              at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
              at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
              at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
              at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
              at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
              at java.lang.Thread.run(Thread.java:619)
      Caused by: javax.ejb.EJBTransactionRolledbackException: EntityManagerFactory not found in JNDI : java:comp/env/myproject/pu
              at org.jboss.ejb3.tx.Ejb3TxPolicy.handleInCallerTx(Ejb3TxPolicy.java:115)
              at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:130)
              at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:194)
              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
              at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
              at org.jboss.ejb3.tx.NullInterceptor.invoke(NullInterceptor.java:42)
              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
              at org.jboss.ejb3.security.RoleBasedAuthorizationInterceptorv2.invoke(RoleBasedAuthorizationInterceptorv2.java:201)
              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
              at org.jboss.ejb3.security.Ejb3AuthenticationInterceptorv2.invoke(Ejb3AuthenticationInterceptorv2.java:186)
              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
              at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:41)
              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
              at org.jboss.ejb3.BlockContainerShutdownInterceptor.invoke(BlockContainerShutdownInterceptor.java:67)
              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
              at org.jboss.aspects.currentinvocation.CurrentInvocationInterceptor.invoke(CurrentInvocationInterceptor.java:67)
              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
              at org.jboss.ejb3.session.SessionSpecContainer.invoke(SessionSpecContainer.java:176)
              at org.jboss.ejb3.session.SessionSpecContainer.invoke(SessionSpecContainer.java:216)
              at org.jboss.ejb3.proxy.impl.handler.session.SessionProxyInvocationHandlerBase.invoke(SessionProxyInvocationHandlerBase.java:207)
              at org.jboss.ejb3.proxy.impl.handler.session.SessionProxyInvocationHandlerBase.invoke(SessionProxyInvocationHandlerBase.java:164)
              at $Proxy639.getUserByLogin(Unknown Source)
              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.seam.util.Reflections.invoke(Reflections.java:22)
              at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:32)
              at org.jboss.seam.intercept.ClientSideInterceptor$1.proceed(ClientSideInterceptor.java:76)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
              at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
              at org.jboss.seam.intercept.ClientSideInterceptor.invoke(ClientSideInterceptor.java:54)
              at org.javassist.tmp.java.lang.Object_$$_javassist_seam_2.getUserByLogin(Object_$$_javassist_seam_2.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 org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:335)
              at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:280)
              at org.jboss.el.parser.AstMethodSuffix.getValue(AstMethodSuffix.java:59)
              at org.jboss.el.parser.AstValue.getValue(AstValue.java:67)
              at org.jboss.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
              at com.sun.facelets.el.ELText$ELTextVariable.writeText(ELText.java:184)
              at com.sun.facelets.el.ELText$ELTextComposite.writeText(ELText.java:108)
              at com.sun.facelets.compiler.TextInstruction.write(TextInstruction.java:45)
              ... 53 more
      Caused by: java.lang.IllegalArgumentException: EntityManagerFactory not found in JNDI : java:comp/env/myproject/pu
              at org.jboss.seam.persistence.ManagedPersistenceContext.getEntityManagerFactoryFromJndiOrValueBinding(ManagedPersistenceContext.java:245)
              at org.jboss.seam.persistence.ManagedPersistenceContext.initEntityManager(ManagedPersistenceContext.java:78)
              at org.jboss.seam.persistence.ManagedPersistenceContext.getEntityManager(ManagedPersistenceContext.java:107)
              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.seam.util.Reflections.invoke(Reflections.java:22)
              at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144)
              at org.jboss.seam.Component.callComponentMethod(Component.java:2249)
              at org.jboss.seam.Component.unwrap(Component.java:2275)
              at org.jboss.seam.Component.getInstance(Component.java:2041)
              at org.jboss.seam.Component.getInstance(Component.java:1983)
              at org.jboss.seam.Component.getInstance(Component.java:1977)
              at org.jboss.seam.Namespace.getComponentInstance(Namespace.java:55)
              at org.jboss.seam.Namespace.getComponentInstance(Namespace.java:50)
              at org.jboss.seam.el.SeamELResolver.resolveBase(SeamELResolver.java:148)
              at org.jboss.seam.el.SeamELResolver.getValue(SeamELResolver.java:51)
              at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
              at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:72)
              at org.jboss.el.parser.AstIdentifier.getValue(AstIdentifier.java:44)
              at org.jboss.el.parser.AstValue.getTarget(AstValue.java:34)
              at org.jboss.el.parser.AstValue.invoke(AstValue.java:95)
              at org.jboss.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
              at org.jboss.seam.core.Expressions$2.invoke(Expressions.java:175)
              at org.jboss.seam.Component.getInstanceFromFactory(Component.java:2063)
              at org.jboss.seam.Component.getInstance(Component.java:2011)
              at org.jboss.seam.Component.getInstance(Component.java:1983)
              at org.jboss.seam.Component.getInstance(Component.java:1977)
              at org.jboss.seam.Component.getInstanceInAllNamespaces(Component.java:2349)
              at org.jboss.seam.Component.getValueToInject(Component.java:2301)
              at org.jboss.seam.Component.injectAttributes(Component.java:1736)
              at org.jboss.seam.Component.inject(Component.java:1554)
              at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:61)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.persistence.EntityManagerProxyInterceptor.aroundInvoke(EntityManagerProxyInterceptor.java:29)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.persistence.HibernateSessionProxyInterceptor.aroundInvoke(HibernateSessionProxyInterceptor.java:30)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
              at org.jboss.seam.intercept.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:50)
              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.ejb3.interceptors.aop.EJB3InterceptorInterceptor.invoke(EJB3InterceptorInterceptor.java:83)
              at org.jboss.ejb3.interceptors.aop.EJB3InterceptorInterceptor.invoke(EJB3InterceptorInterceptor.java:70)
              at org.jboss.ejb3.EJBContainerInvocationWrapper.invokeNext(EJBContainerInvocationWrapper.java:59)
              at org.jboss.ejb3.interceptors.aop.InterceptorSequencer.invoke(InterceptorSequencer.java:73)
              at org.jboss.ejb3.interceptors.aop.InterceptorSequencer.aroundInvoke(InterceptorSequencer.java:59)
              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.aop.advice.PerJoinpointAdvice.invoke(PerJoinpointAdvice.java:174)
              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
              at org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor.fillMethod(InvocationContextInterceptor.java:72)
              at org.jboss.aop.advice.org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor_z_fillMethod_29313387.invoke(InvocationContextInterceptor_z_fillMethod_29313387.java)
              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
              at org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor.setup(InvocationContextInterceptor.java:88)
              at org.jboss.aop.advice.org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor_z_setup_29313387.invoke(InvocationContextInterceptor_z_setup_29313387.java)
              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
              at org.jboss.ejb3.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:62)
              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
              at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:56)
              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
              at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
              at org.jboss.ejb3.tx.NullInterceptor.invoke(NullInterceptor.java:42)
              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
              at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:68)
              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
              at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:126)
              ... 97 more
      Caused by: javax.naming.NameNotFoundException: myproject not bound
              at org.jnp.server.NamingServer.getBinding(NamingServer.java:771)
              at org.jnp.server.NamingServer.getBinding(NamingServer.java:779)
              at org.jnp.server.NamingServer.getObject(NamingServer.java:785)
              at org.jnp.server.NamingServer.lookup(NamingServer.java:396)
              at org.jnp.server.NamingServer.lookup(NamingServer.java:399)
              at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:726)
              at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:833)
              at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:686)
              at javax.naming.InitialContext.lookup(InitialContext.java:392)
              at org.jboss.seam.persistence.ManagedPersistenceContext.getEntityManagerFactoryFromJndiOrValueBinding(ManagedPersistenceContext.java:241)
              ... 171 more
      



        • 1. Re: EntityManagerFactory not found in JNDI (project created by seam-gen)
          Arbi Sookazian Master

          have you tried doing it the way it's done in seam booking project?

          • 2. Re: EntityManagerFactory not found in JNDI (project created by seam-gen)
            slawek t Novice

            I tried to follow http://relation.to/10827.lace with no success. I'll look at the booking example.

            • 3. Re: EntityManagerFactory not found in JNDI (project created by seam-gen)
              Arbi Sookazian Master

              Don't follow that article, it's for Glassfish, you're using JBoss and the JNDI patterns are different for these two app servers (read about it in the Seam ref doc).


              Follow the seam-booking app, or any other Seam example project for JBoss AS...

              • 4. Re: EntityManagerFactory not found in JNDI (project created by seam-gen)
                slawek t Novice

                Finally, it's working and configuration is based on Booking example (JPA) and it looks like this:



                components.xml


                ...
                     <persistence:managed-persistence-context
                          name="entityManager" auto-create="true" 
                          persistence-unit-jndi-name="java:/myprojectEntityManagerFactory" />
                
                     <factory name="session" method="#{entityManager.getDelegate( )}"
                          scope="STATELESS" auto-create="true" />
                ...
                



                persistence-dev.xml


                ...
                <?xml version="1.0" encoding="UTF-8"?>
                <!-- Persistence deployment descriptor for dev profile -->
                <persistence 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" 
                             version="1.0">
                             
                   <persistence-unit name="myproject">
                      <provider>org.hibernate.ejb.HibernatePersistence</provider>
                      <jta-data-source>myprojectDatasource</jta-data-source>
                      <!-- The <jar-file> element is necessary if you put the persistence.xml in the WAR and the classes in the JAR -->
                      <!--
                      <jar-file>../../vehicles.jar</jar-file>
                      -->
                      <properties>
                         <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
                         <property name="hibernate.hbm2ddl.auto" value="update"/>
                         <property name="hibernate.show_sql" value="true"/>
                         <property name="hibernate.format_sql" value="true"/>
                         <property name="jboss.entity.manager.factory.jndi.name" value="java:/myprojectEntityManagerFactory"/>
                      </properties>
                   </persistence-unit>
                    
                </persistence>
                ...
                



                web.xml


                completely removed


                <persistence-unit-ref>...</persistence-unit-ref>
                



                Thank you Arbi for your suggestions.

                • 5. Re: EntityManagerFactory not found in JNDI (project created by seam-gen)
                  shane lee Newbie

                  I seem to get that problem too, thanks for the reply Slawek.
                  I find its an issue around seam generated CRUD applications when instead of extending EntityHome class your bean/POJO injects in EntityManager.