0 Replies Latest reply on Jun 1, 2006 6:28 PM by Giancarlo Corzo

    CreateEntityManagerFactory problem

    Giancarlo Corzo Newbie

      I trying to get a EntityManagerFactory from a POJO using this code:

      private EntityManagerFactory emf;
      ....
      emf = Persistence.createEntityManagerFactory("fonocontrolDatabase");
      
      


      but when I run the app I get and Exception.

      I'm using Seam with the embedded microcontainer in a Tomcat server so
      I think the problem is with the tomcat JNDI beacuse the datasource its in the microcontainer and the method it's looking in the in the wrong enviroment.

      FATAL 01-06 17:04:41,781 (DatasourceConnectionProvider.java:configure:55) -Could not find datasource: java:/fonocontrolDatasource
      javax.naming.NameNotFoundException: El nombre fonocontrolDatasource no este asociado a este contexto
       at org.apache.naming.NamingContext.lookup(NamingContext.java:769)
       at org.apache.naming.NamingContext.lookup(NamingContext.java:152)
       at org.apache.naming.SelectorContext.lookup(SelectorContext.java:136)
       at javax.naming.InitialContext.lookup(InitialContext.java:351)
       at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:52)
       at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
       at org.hibernate.ejb.InjectionSettingsFactory.createConnectionProvider(InjectionSettingsFactory.java:28)
       at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:61)
       at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1885)
       at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1178)
       at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:500)
       at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:627)
       at org.hibernate.ejb.Ejb3Configuration.createFactory(Ejb3Configuration.java:126)
       at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:180)
       at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:110)
       at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:37)
       at com.antartec.fonocontrol.procesador.bean.impl.ProcesadorEntityManagerBean.<init>(ProcesadorEntityManagerBean.java:35)
       at com.antartec.fonocontrol.procesador.bean.impl.ProcesadorEntityManagerBean.getInstance(ProcesadorEntityManagerBean.java:30)
       at com.antartec.fonocontrol.procesador.bean.impl.ParserBeanThread.getEntityManager(ParserBeanThread.java:118)
       at com.antartec.fonocontrol.procesador.bean.impl.ParserBeanThread.run(ParserBeanThread.java:63)
      javax.persistence.PersistenceException: org.hibernate.HibernateException: Could not find datasource
       at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:188)
       at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:110)
       at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:37)
       at com.antartec.fonocontrol.procesador.bean.impl.ProcesadorEntityManagerBean.<init>(ProcesadorEntityManagerBean.java:35)
       at com.antartec.fonocontrol.procesador.bean.impl.ProcesadorEntityManagerBean.getInstance(ProcesadorEntityManagerBean.java:30)
       at com.antartec.fonocontrol.procesador.bean.impl.ParserBeanThread.getEntityManager(ParserBeanThread.java:118)
       at com.antartec.fonocontrol.procesador.bean.impl.ParserBeanThread.run(ParserBeanThread.java:63)
      Caused by: org.hibernate.HibernateException: Could not find datasource
       at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:56)
       at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
       at org.hibernate.ejb.InjectionSettingsFactory.createConnectionProvider(InjectionSettingsFactory.java:28)
       at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:61)
       at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1885)
       at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1178)
       at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:500)
       at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:627)
       at org.hibernate.ejb.Ejb3Configuration.createFactory(Ejb3Configuration.java:126)
       at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:180)
       ... 6 more
      


      My Persistent.xml:

       <persistence-unit name="fonocontrolDatabase">
       <provider>org.hibernate.ejb.HibernatePersistence</provider>
       <jta-data-source>java:/fonocontrolDatasource</jta-data-source>
       <properties>
       <!--<property name="hibernate.hbm2ddl.auto" value="update"/>-->
       <property name="hibernate.cache.use_query_cache" value="true"/>
       <property name="hibernate.show_sql" value="false"/>
       <property name="jboss.entity.manager.factory.jndi.name" value="java:/EntityManagerFactories/fonocontrolData"/>
       <property name="jboss.entity.manager.jndi.name" value="java:/fonocontrolEntityManager" />
       </properties>
       </persistence-unit>


      My Jboss-bean.xml

       <bean name="fonocontrolDatasourceBootstrap" class="org.jboss.resource.adapter.jdbc.local.LocalTxDataSource">
       <property name="driverClass">com.mysql.jdbc.Driver</property>
       <property name="connectionURL">jdbc:mysql://192.168.1.100:3306/fonocontrol</property>
       <property name="userName">fonocontrol</property>
       <property name="password">fonocontrol</property>
       <property name="jndiName">java:/fonocontrolDatasource</property>
       <property name="minSize">0</property>
       <property name="maxSize">10</property>
       <property name="blockingTimeout">1000</property>
       <property name="idleTimeout">100000</property>
       <property name="transactionManager"><inject bean="TransactionManager"/></property>
       <property name="cachedConnectionManager"><inject bean="CachedConnectionManager"/></property>
       <property name="initialContextProperties"><inject bean="InitialContextProperties"/></property>
       </bean>
      
       <bean name="fonocontrolDatasource" class="java.lang.Object">
       <constructor factoryMethod="getDatasource">
       <factory bean="fonocontrolDatasourceBootstrap"/>
       </constructor>
       </bean>


      the web.xml

       <context-param>
       <param-name>org.jboss.seam.core.init.managedPersistenceContexts</param-name>
       <param-value>seguridadDatabase fonocontrolDatabase</param-value>
       </context-param>
      
       <context-param>
       <param-name>seguridadDatabase.persistenceUnitJndiName</param-name>
       <param-value>java:/EntityManagerFactories/seguridadData</param-value>
       </context-param>
      
       <context-param>
       <param-name>fonocontrolDatabase.persistenceUnitJndiName</param-name>
       <param-value>java:/EntityManagerFactories/fonocontrolData</param-value>
       </context-param>