You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Doug Reeder <re...@gmail.com> on 2008/10/27 10:11:57 UTC

Can't Create Tables

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();
         }
     }

Re: Can't Create Tables

Posted by Doug Reeder <re...@gmail.com>.
Thanks!

I tried again, setting persistence to use JTA transactions, and  
specifying the connection using openjpa properties, instead of a  
DataSource, and the problem turns out to be the DataSource:  Geronimo  
prefers to use Geronimo names to identify resources, and has arcane  
procedures to use JNDI names.

I gave up (for now) on trying to use JNDI names with Geronimo.   
Unfortunately, this means I need a different persistence.xml file for  
Geronimo. :-(



On Oct 27, 2008, at 1:19 PM, Jeremy Bauer wrote:

> Hi Doug,
>
> By setting openjpa.jdbc.SynchronizeMappings property to the value
> you've specified, the schema should be created for you.  You could try
> enabling OpenJPA trace to see if there are any messages in the log
> that may show whether there was a problem during the the schema
> creation process.  There also could be a schema mismatch or other
> config issue.  The trace may help determine that as well.
>
> Full trace can typically be enabled with the following property,
> unless Geronimo overrides the default trace facility/configuration.
>
> <property  name="openjpa.Log"  value="DefaultLevel=TRACE"/>
>
> -Jeremy


Re: Can't Create Tables

Posted by Jeremy Bauer <te...@gmail.com>.
Hi Doug,

By setting openjpa.jdbc.SynchronizeMappings property to the value
you've specified, the schema should be created for you.  You could try
enabling OpenJPA trace to see if there are any messages in the log
that may show whether there was a problem during the the schema
creation process.  There also could be a schema mismatch or other
config issue.  The trace may help determine that as well.

Full trace can typically be enabled with the following property,
unless Geronimo overrides the default trace facility/configuration.

<property  name="openjpa.Log"  value="DefaultLevel=TRACE"/>

-Jeremy