DDL generation and general persistence.xml settings (OpenJPA)

后端 未结 2 935
星月不相逢
星月不相逢 2021-01-05 03:46

Summary

I\'m trying to run a Java web application JPA 2.0 example. The example application was written to run in Glassfish, using

相关标签:
2条回答
  • 2021-01-05 04:05

    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

    0 讨论(0)
  • 2021-01-05 04:24

    Foreign key constraints

    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"/>
    

    See generated SQL

    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

    0 讨论(0)
提交回复
热议问题