openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Doug Reeder <reeder...@gmail.com>
Subject Can't Create Tables
Date Mon, 27 Oct 2008 09:11:57 GMT
I created a small test project in Eclipse (v 3.4.1) which I attempt to  
deploy to a Geronimo (v 2.1.3) server, with the default OpenJPA 1.0.3  
installed, running under OS X 10.5.5.  There's only one entity class,  
learn.eclipse.Person.

Using  the first persistence-unit definition in my persistence.xml  
file below (now commented out) which uses RESOURCE_LOCAL transactions  
and directly specifies the connection, the test app ran fine, creating  
a new record in the database every time it was run.   Using the second  
definition, which uses JTA transactions and a Datasource  
(learnEclipseWebPool) defined on the server, I always get the error
04:29:23,680 WARN  [Transaction] Unexpected exception from  
beforeCompletion; transaction will roll back
<openjpa-1.0.3-r420667:677674 fatal general error>  
org.apache.openjpa.persistence.PersistenceException: The transaction  
has been rolled back.  See the nested exceptions for details on the  
errors that occurred.
...
NestedThrowables:
java.sql.SQLException: Table/View 'PERSON' does not exist.
...
Caused by: ERROR 42X05: Table/View 'PERSON' does not exist.


No warnings show up in the log before
my persistence.xml file is:
<?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="LearnEclipseWebLocal" transaction- 
type="RESOURCE_LOCAL">
		<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</ 
provider>
		<properties>
			<property name="openjpa.ConnectionURL" value="jdbc:derby:/usr/local/ 
derby/LearnPeople" />
			<property name="openjpa.ConnectionDriverName"  
value="org.apache.derby.jdbc.ClientDriver" />
		</properties>
	</persistence-unit>
	-->
	<persistence-unit name="LearnEclipseWebJTA" transaction-type="JTA">
		<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</ 
provider>
		<jta-data-source>learnEclipseWebPool</jta-data-source>
		<non-jta-data-source>NoTxDatasource</non-jta-data-source>
		<class>learn.eclipse.Person</class>
		<!-- <jar-file>LearnEclipseWeb2.war</jar-file> -->
     	<properties>
			<property name="openjpa.jdbc.SynchronizeMappings"  
value="buildSchema(ForeignKeys=true)"/>
     		
     		<!--
       		<property name="openjpa.jdbc.DBDictionary" value="derby"/>
       		<property name="openjpa.jdbc.Schema" value="APP"/>
       		-->
    		</properties>
	</persistence-unit>
</persistence>

 From reading the docs, I gathered that all I needed to do to get  
OpenJPA  to create the tables is naming all the classes in the  
persistence.xml file and setting the property  
openjpa.jdbc.SynchronizeMappings.  Do I need to do something more?

The Java code which does the persistence (in the Web tier) is:

     public void persist(Object entity) {
         EntityManager em = emf.createEntityManager();
         System.out.println("LearnEclipseWeb2: EntityTransaction  
begun");
         try {
             utx.begin();
             System.out.println("LearnEclipseWeb2: UserTransaction  
begun");

             em.joinTransaction();   // JTA

             em.persist(entity);
             System.out.println("LearnEclipseWeb2: persisted " +  
entity);

             utx.commit();
             System.out.println("LearnEclipseWeb2: UserTransaction  
committed");
         } catch (javax.transaction.RollbackException ex) {   // from  
utx.commit()
             System.out.print(ex);
         } catch (javax.transaction.HeuristicMixedException ex) {   //  
from utx.commit()
             System.out.print(ex);
         } catch (javax.transaction.HeuristicRollbackException ex)  
{   // from utx.commit()
             System.out.print(ex);
         } catch (javax.transaction.NotSupportedException ex) {   //  
from utx.begin()
             System.out.print(ex);
         } catch (javax.transaction.SystemException ex) {   // from  
utx.begin()
             System.out.print(ex);
         } catch (RuntimeException ex) {
         	throw ex;
         } finally {
             em.close();
         }
     }
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message