5 Replies Latest reply on Sep 29, 2011 4:33 PM by Scott Marlow

    javax.naming.NameNotFoundException: Name 'Manager1Factory' not found in context ''

    Red Militante Newbie

      I get the error

       

       

        

       javax.naming.NameNotFoundException: Name 'Manager1Factory' not found in context ''
      

       

       

      when I try to deploy my hibernate app in JBoss 7.  The line of code that is throwing this exception looks like

       

       

              entityManagerFactory = (EntityManagerFactory)ctx.lookup("java:/Manager1Factory");
          EntityManager entityManager = entityManagerFactory.createEntityManager();
      

       

      I have the JNDI name defined in persistence.xml like

       

          <?xml version="1.0" encoding="UTF-8"?>
          <persistence version="2.0"
             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_2_0.xsd">
             <persistence-unit name="primary2">
                <!-- If you are running in a production environment, add a managed 
                   data source, the example data source is just for proofs of concept! -->
                <!-- We may want to make this a jta-data-source and let the container create     entityManagers/look up EntityManagers via JNDI in our business objs -->
                <non-jta-data-source>java:jboss/datasources/MySqlDS2</non-jta-data-source>             
                          <class>com.mycompany.myapp.anywhere.common.businessobjects.CurrentTransaction</class>                                      
                  <class>com.mycompany.myapp.anywhere.common.businessobjects.ServerSettings</class>                                      
                  <class>com.mycompany.myapp.anywhere.common.persistence.HibernateUtil</class>                           
            
            <properties>
               <!-- Properties for Hibernate -->
               <!-- <sproperty name="hibernate.hbm2ddl.auto" value="create-drop" /> -->
               <!-- <property name="hibernate.show_sql" value="false" /> -->
               <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
               <property name="hibernate.ejb.interceptor.session_scoped" value="com.mycompany.myapp.anywhere.common.persistence.BusinessObjectInterceptor"/>
               <property name="jboss.entity.manager.jndi.name" value="java:/Manager1"/>           
               <property name="jboss.entity.manager.factory.jndi.name" value="java:/Manager1Factory"/>  
               </properties>
             </persistence-unit>
          </persistence>
      

       

       

       

       

       

      I'm not sure why I'm receiving this error - when I check the JBoss console I see the name Manager1Factory shows up under JNDI bindings, so it seems like the EntityManagerFactory is being created but it is not being injected into my class?  Any ideas why this is happening?  Thanks!

        • 1. Re: javax.naming.NameNotFoundException: Name 'Manager1Factory' not found in context ''
          Wolf-Dieter Fink Master

          Why you don't use:

           

          @PersistenceContext(unitName="primary2")

          EnityManager primary2;

           

          This should work perfect for JEE applications

          • 2. Re: javax.naming.NameNotFoundException: Name 'Manager1Factory' not found in context ''
            Red Militante Newbie

            My app uses an application managed entity manager.  I believe I'm supposed to use @PersistenceUnit. 

             

            http://community.jboss.org/thread/172624?tstart=0

            I tried using @PersistenceUnit but had some problems in this thread.

            • 3. Re: javax.naming.NameNotFoundException: Name 'Manager1Factory' not found in context ''
              Scott Marlow Master

              I don't think the jndi name "java:/Manager1Factory" will  work.  Try something like "java:global/persistence/Manager1Factory".

               

              Regarding http://community.jboss.org/thread/172624?tstart=0, I missed that posting.  If you don't mind, could you try again against the latest nightly build (http://community.jboss.org/thread/167590) and create a jira (https://issues.jboss.org/browse/AS7) if its still broken.

              • 4. Re: javax.naming.NameNotFoundException: Name 'Manager1Factory' not found in context ''
                Red Militante Newbie

                I tried this in persistence.xml

                 

                 

                 

                 

                <property name="jboss.entity.manager.jndi.name" value="java:global/persistence/Manager1"/>
                         <property name="jboss.entity.manager.factory.jndi.name" value="java:global/persistence/Manager1Factory"/>  
                
                

                 

                 

                and this in my class

                 

                 

                 

                 

                entityManagerFactory = (EntityManagerFactory)ctx.lookup("java:global/persistence/Manager1Factory");
                                EntityManager entityManager = entityManagerFactory.createEntityManager();
                

                 

                I get this stack trace when I attempt to deploy my app in JBoss-as-7.0.1-Final

                 

                15:16:18,491 ERROR [com.mycompany.myapp.common.persistence.HibernateUtil] (MSC service thread 1-10) Initial SessionFactory lookup failed.: javax.persistence.PersistenceException: No Persistence provider for EntityManager named primary2
                        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:69) [hibernate-jpa-2.0-api-1.0.1.Final.jar:1.0.1.Final]
                        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47) [hibernate-jpa-2.0-api-1.0.1.Final.jar:1.0.1.Final]
                        at com.mycompany.myapp.common.persistence.HibernateUtil.<clinit>(HibernateUtil.java:37) [classes:]
                        at com.mycompany.myapp.common.businessobjects.ServerSettings.GetServerSettings(ServerSettings.java:84) [classes:]
                        at com.mycompany.myapp.common.jms.JMSListenerServletTemplate.init(JMSListenerServletTemplate.java:41) [classes:]
                        at com.mycompany.myapp.common.jms.JMSAnywhereServlet.init(JMSAnywhereServlet.java:179) [classes:]
                        at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1202) [jbossweb-7.0.1.Final.jar:7.0.1.Final]
                        at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1102) [jbossweb-7.0.1.Final.jar:7.0.1.Final]
                        at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3631) [jbossweb-7.0.1.Final.jar:7.0.1.Final]
                        at org.apache.catalina.core.StandardContext.start(StandardContext.java:3844) [jbossweb-7.0.1.Final.jar:7.0.1.Final]
                        at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:70) [jboss-as-web-7.0.1.Final.jar:7.0.1.Final]
                        at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1765)
                        at org.jboss.msc.service.ServiceControllerImpl$ClearTCCLTask.run(ServiceControllerImpl.java:2291)
                        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_26]
                        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_26]
                        at java.lang.Thread.run(Thread.java:680) [:1.6.0_26]a
                
                

                 

                 

                 

                 

                I'd rather use the @PersistenceUnit annotation, so I'll try the nightly build and update you.

                • 5. Re: javax.naming.NameNotFoundException: Name 'Manager1Factory' not found in context ''
                  Scott Marlow Master

                  Hmm, sorry about that, how about "java:jboss/entitymanager/MyPUManagerFactory".  That worked for someone else http://community.jboss.org/message/622882#622882

                   

                  Scott