tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Blevins <david.blev...@visi.com>
Subject Re: OpenEJB - Missing required persistence.xml
Date Fri, 15 Feb 2008 22:55:05 GMT

On Feb 15, 2008, at 9:36 AM, <Karsten.Ohme@t-systems.com> <Karsten.Ohme@t-systems.com

 > wrote:

> Hi,
>
> well it works now. Because I have changed the persistence provider  
> to Hibernate. The problem now is that entities are not persisted.  
> persist() simply does nothing. But no error is shown.
>
> The persistence.xml is as follows. I have also a full log of the  
> whole Hibernate. I cannot find an error.
>
> <?xml version="1.0" encoding="UTF-8"?>
> <persistence version="1.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_1_0.xsd

> ">
> 	<persistence-unit name="testFacadePu" transaction- 
> type="RESOURCE_LOCAL">
> 		<provider>org.hibernate.ejb.HibernatePersistence</provider>
> 		<non-jta-data-source>java:jdbc/DerbyDatabase</non-jta-data-source>
> 		<properties>
>  			<property name="hibernate.hbm2ddl.auto" value="create-drop" />
> 			<property name="openjpa.jdbc.SynchronizeMappings"
> 				value="buildSchema(ForeignKeys=true)" />
> 			<property name="hibernate.hbm2ddl.auto" value="create-drop" />
> 		</properties>
> 	</persistence-unit>
> </persistence>

I'd definitely use transaction-type="TRANSACTION" instead of  
transaction-type="RESOURCE_LOCAL" with either OpenJPA or Hibernate.   
RESOURCE_LOCAL is very difficult to use and transaction- 
type="TRANSACTION" is not slow like people normally think.  At the  
very least, start with the default of transaction-type="TRANSACTION",  
get that to work and switch it later if it's still important.

Regardless of if you use transaction-type="RESOURCE_LOCAL" or  
transaction-type="TRANSACTION" you definitely should supply both <jta- 
data-source> and <non-jta-data-source>.

The DataSource for the jta-data-source should always have it's  
'JtaManaged' property set to 'true' (this is the default)
The DataSource for the non-jta-data-source should always have it's  
'JtaManaged' property set to 'false'.

In your test code, you could do it like this:


       if (DB_MODE == MYSQL) {
           properties.setProperty("MySqlDatabase", "new://Resource? 
type=DataSource");
           properties.setProperty("MySqlDatabase.JdbcUrl",  
"jdbc:mysql://localhost:3306/tpg-server");
           properties.setProperty("MySqlDatabase.JdbcDriver",  
"com.mysql.jdbc.Driver");
           properties.setProperty("MySqlDatabase.UserName", "tpg");
           properties.setProperty("MySqlDatabase.Password", "tpg");

           properties.setProperty("MySqlDatabaseUnmanaged", "new:// 
Resource?type=DataSource");
           properties.setProperty("MySqlDatabaseUnmanaged.JdbcUrl",  
"jdbc:mysql://localhost:3306/tpg-server");
           properties.setProperty("MySqlDatabaseUnmanaged.JdbcDriver",  
"com.mysql.jdbc.Driver");
           properties.setProperty("MySqlDatabaseUnmanaged.UserName",  
"tpg");
           properties.setProperty("MySqlDatabaseUnmanaged.Password",  
"tpg");
           properties.setProperty("MySqlDatabaseUnmanaged.JtaManaged",  
"false");
       } else if (DB_MODE == DERBY) {
           properties.setProperty("DerbyDatabase", "new://Resource? 
type=DataSource");
           properties.setProperty("DerbyDatabase.JdbcUrl",  
"jdbc:derby:derbyDB;create=true");
           properties.setProperty("DerbyDatabase.JdbcDriver",  
"org.apache.derby.jdbc.EmbeddedDriver");

           properties.setProperty("DerbyDatabaseUnmanaged", "new:// 
Resource?type=DataSource");
           properties.setProperty("DerbyDatabaseUnmanaged.JdbcUrl",  
"jdbc:derby:derbyDB;create=true");
           properties.setProperty("DerbyDatabaseUnmanaged.JdbcDriver",  
"org.apache.derby.jdbc.EmbeddedDriver");
           properties.setProperty("DerbyDatabaseUnmanaged.JtaManaged",  
"false");
       }


-David



Mime
View raw message