Summary
I\'m trying to run a Java web application JPA 2.0 example. The example application was written to run in Glassfish
, using
If you add the openjpa.jdbc.SynchronizeMappings
property as shown below OpenJPA will auto-create all your tables, all your primary keys and all foreign keys exactly to match your objects
<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/>
Alternatively, you can use EclipseLink in TomEE by just adding the EclipseLink jars to <CATALINA_HOME>/lib/
refer here for Common PersistenceProvider properties
The next line does not create foreign keys:
<property name="openjpa.jdbc.SynchronizeMappings"
value="buildSchema(ForeignKeys=true)"/>
Only creates schema and deletes content of a database.
But if you want create foreign keys, use the following lines:
<property name="openjpa.jdbc.SynchronizeMappings"
value="buildSchema(foreignKeys=true,schemaAction='dropDB,add')"/>
<property name="openjpa.jdbc.SchemaFactory"
value="native(foreignKeys=true)" />
<property name="openjpa.jdbc.MappingDefaults"
value="ForeignKeyDeleteAction=restrict, JoinForeignKeyDeleteAction=restrict"/>
In another way, if you want to see the SQL output:
<property name="openjpa.Log"
value="DefaultLevel=TRACE,SQL=TRACE" />
NOTE: In order to see the generated output in the TomEE console, you need to change the log level in the file loggin.properties
with openjpa.level = FINEST
See more in http://openjpa.apache.org/faq.html