4 Replies Latest reply on Jun 10, 2009 12:38 AM by gonorrhea

    EntityManagerFactory not found in JNDI (not bound)

    gonorrhea

      I'm not sure why I'm seeing this stack trace seemingly in an infinite loop when I navigate to the home xhtml of my web app:


      Caused by: java.lang.IllegalArgumentException: EntityManagerFactory not found in JNDI : java:/EquipmentRecoveryEntityManagerFactory
              at org.jboss.seam.persistence.ManagedPersistenceContext.getEntityManagerFactoryFromJndiOrValueBinding(ManagedPersistenceContext.java:247)
              at org.jboss.seam.persistence.ManagedPersistenceContext.initEntityManager(ManagedPersistenceContext.java:79)
              at org.jboss.seam.persistence.ManagedPersistenceContext.getEntityManager(ManagedPersistenceContext.java:108)
              at sun.reflect.GeneratedMethodAccessor174.invoke(Unknown Source)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:585)
              at org.jboss.seam.util.Reflections.invoke(Reflections.java:21)
              at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:125)
              at org.jboss.seam.Component.callComponentMethod(Component.java:2092)
              at org.jboss.seam.Component.unwrap(Component.java:2118)
              at org.jboss.seam.Component.getInstance(Component.java:1890)
              at org.jboss.seam.Component.getInstance(Component.java:1843)
              at org.jboss.seam.Component.getInstanceInAllNamespaces(Component.java:2192)
              at org.jboss.seam.Component.getValueToInject(Component.java:2144)
              at org.jboss.seam.Component.injectAttributes(Component.java:1601)
              at org.jboss.seam.Component.inject(Component.java:1419)
              at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:45)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:42)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.persistence.EntityManagerProxyInterceptor.aroundInvoke(EntityManagerProxyInterceptor.java:26)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.persistence.HibernateSessionProxyInterceptor.aroundInvoke(HibernateSessionProxyInterceptor.java:27)
              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.GeneratedMethodAccessor172.invoke(Unknown Source)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:585)
              at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:118)
              at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
              at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
              at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
              at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:126)
              ... 110 more
      Caused by: javax.naming.NameNotFoundException: EquipmentRecoveryEntityManagerFactory not bound
              at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
              at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
              at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
              at org.jnp.server.NamingServer.lookup(NamingServer.java:296)
              at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:667)
              at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:627)
              at javax.naming.InitialContext.lookup(InitialContext.java:351)
              at org.jboss.seam.persistence.ManagedPersistenceContext.getEntityManagerFactoryFromJndiOrValueBinding(ManagedPersistenceContext.java:243)
              ... 146 more



      foo-ds.xml:


         <local-tx-datasource>
            <jndi-name>EquipmentRecoveryDatasource</jndi-name>
            <connection-url>jdbc:sqlserver://CORG0DB901:1433;databaseName=EquipmentRecovery</connection-url>
            <driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class>
            <user-name>_AppUser_JavaTestAcct</user-name>
            <password>JavaTestAcct</password>     
         </local-tx-datasource>



      persistence.xml:


      <persistence-unit name="EquipmentRecovery">
            <provider>org.hibernate.ejb.HibernatePersistence</provider>
            <jta-data-source>java:/EquipmentRecoveryDatasource</jta-data-source>
            <properties>
               <property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect"/>
               <property name="hibernate.hbm2ddl.auto" value="validate"/>
               <property name="hibernate.show_sql" value="true"/>
               <property name="hibernate.format_sql" value="true"/>
               <property name="hibernate.generate_statistics" value="true"/>
               <property name="jboss.entity.manager.factory.jndi.name" value="java:/EquipmentRecoveryEntityManagerFactory"/>
               <property name="hibernate.default_catalog" value="EquipmentRecovery"/>
               <property name="hibernate.default_schema" value="dbo"/>
            </properties>
         </persistence-unit>



      components.xml:


       <persistence:managed-persistence-context name="entityManager"
                                           auto-create="true"
                            persistence-unit-jndi-name="java:/EquipmentRecoveryEntityManagerFactory"/> 



      Any idea why this is happening?  thx.

        • 1. Re: EntityManagerFactory not found in JNDI (not bound)
          gonorrhea

          Well, the answer must have something to do with what's going on in the org.jboss.seam.persistence.ManagedPersistenceContext class:


          public EntityManagerFactory getEntityManagerFactoryFromJndiOrValueBinding()
             {
                EntityManagerFactory result = null;
                //first try to find it via the value binding
                if (entityManagerFactory!=null)
                {
                   result = entityManagerFactory.getValue();
                }
                //if its not there, try JNDI
                if (result==null)
                {
                   try
                   {
                      result = (EntityManagerFactory) Naming.getInitialContext().lookup(persistenceUnitJndiName);
                   }
                   catch (NamingException ne)
                   {
                      throw new IllegalArgumentException("EntityManagerFactory not found in JNDI : " + persistenceUnitJndiName, ne);
                   }
                }
                return result;
             }



          So the lookup call is throwing a NamingException, which means that persistenceUnitJndiName is not in the JNDI naming environment.


          So the question is, why wasn't the persistenceUnitJndiName added to the JNDI naming envmt?  When/where does that happen?

          • 2. Re: EntityManagerFactory not found in JNDI (not bound)
            arshadm

            Hi,


            I think you need to look further up in the log file, there may be a problem with your persistence unit or some error in your entity definitions which is why the persistence unit is not being initialised and which in turn is causing the entity manager not being available.


            Regards.

            • 3. Re: EntityManagerFactory not found in JNDI (not bound)
              gonorrhea

              only reference to Naming.setInitialContext* is in org.jboss.seam.init.Initialization:


              private void initJndiProperties()
                 {
                    Properties jndiProperties = new Properties();
                    jndiProperties.putAll(loadFromResource("/jndi.properties"));
                    jndiProperties.putAll(loadFromResource("/seam-jndi.properties"));
                    Naming.setInitialContextProperties(jndiProperties);
                 }



              'seam-jndi' is not referenced in the Seam ref doc or SiA book.  Anybody actually use that properties file?


              I don't have a seam-jndi.properties or jndi.properties in my project.

              • 4. Re: EntityManagerFactory not found in JNDI (not bound)
                gonorrhea

                thanks but apparently the root cause has been fixed.  not sure what I did to fix it but the exception is gone now...