Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

I cannot create a EntityManagerFactory with tomcat

843830Apr 13 2009 — edited Apr 13 2009
Hello everyone.
I hope you could help me with some problem I'm having using persistence (with hibernate annotations) in my web applicacion.

I have a method that receives some pojos to persist. The problem is that I cannot find a way to generate de entitymanagerFactory. whenever I try to do it, the method just finishes without giving any exception. This confuses me.

My persistence.xml:
 
<?xml version="1.0" encoding="UTF-8"?>
<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="FlatFilePU" transaction-type="RESOURCE_LOCAL">
		<provider>org.hibernate.ejb.HibernatePersistence</provider>
		<non-jta-data-source>java:comp/env/l2bdomi</non-jta-data-source>
		
		
  		<properties>
			<property name = "hibernate.connection.driver_class" value = "oracle.jdbc.driver.OracleDriver"/>
			<property name = "hibernate.connection.url" value = "jdbc:oracle:thin:@xx.xx.xx.xx:1521:xxxx"/>
			<property name = "hibernate.connection.username" value = "xxxx"/>
			<property name = "hibernate.connection.password" value = "xxxx"/>
			<property name="hibernate.hbm2ddl.auto" value="update"/>
			<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle9Dialect"/> 

			
	  	</properties>  
	</persistence-unit>
  
</persistence>
and the method that is failing:
public void guardaLote(LoteDomiciliacion lote){
		try{
		System.out.println("1");
		
                              //The following line is the last one that gets executed. 
		EntityManagerFactory emf = Persistence.createEntityManagerFactory("FlatFilePU");  
		EntityManager ent= emf.createEntityManager();
		System.out.println("2");
		ent.getTransaction().begin();

		System.out.println("3");
		loteDao.save(lote);
		System.out.println("4");
		ArrayList<LineaDomiciliacion> lineas=(ArrayList<LineaDomiciliacion>) lote.getLineas();
		Iterator<LineaDomiciliacion> i = lineas.iterator();
		while(i.hasNext()){
			registroDao.save(i.next());
		}
		System.out.println("5");
		ent.getTransaction().commit();
		ent.close();
		
		}catch(Exception e){
			System.out.println("erro2");
			e.printStackTrace();
			
		}
		
	}
extract from tomcat's server.xml:
<GlobalNamingResources>

    <!-- Test entry for demonstration purposes -->
    <Environment name="simpleValue" type="java.lang.Integer" value="30"/>

    <!-- Editable user database that can also be used by
         UserDatabaseRealm to authenticate users -->
    <Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
       description="User database that can be updated and saved"
           factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
          pathname="conf/tomcat-users.xml" />
          
          <Resource name="masterPool" auth="Container" type="java.util.ArrayList" factory="uk.org.primrose.pool.datasource.MasterPoolDataSourceFactory" configFile="C:/Tomcat 5.5/conf/poolConfig.properties" description="Holds all the pools" /> 	  

	    <Resource name="l2bdomi"  auth="Container" type="uk.org.primrose.pool.datasource.PoolDataSource" description="The l2bdomi database pool" factory="uk.org.primrose.pool.datasource.PoolDataSourceFactory" poolName="l2bdomi" /> 
  </GlobalNamingResources>
after EntityManagerFactory emf = Persistence.createEntityManagerFactory("FlatFilePU"); this method an the method that called it (in a servlet) finishes. The only thing that gets executed after that is a finally. I tried to catch Exception but I didnt get any.

My guess is that the problem comes from the datasource configuration but Im not sure since I am new working with datasources.

thank you for any help you can provide me.

Edited by: santiagozky on Apr 13, 2009 2:48 PM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 11 2009
Added on Apr 13 2009
1 comment
577 views