JPA and toplink create-table on if they don't already exist?

女生的网名这么多〃 提交于 2019-12-01 17:13:25

According to http://www.oracle.com/technology/products/ias/toplink/JPA/essentials/toplink-jpa-extensions.html#Java2DBSchemaGen toplink does not have an option to update exiting tables, I'm not sure if I would trust it to do the right thing anyway. You could configure toplink to generate a sql script that you then would have to execute manually to create all tables. The filenames and location can be configured like this:

<property name="toplink.ddl-generation" value="create-tables"/>
<property name="toplink.ddl-generation.output-mode" value="sql-script"/>
<property name="toplink.create-ddl-jdbc-file-name" value="createDDL.sql"/>
<property name="toplink.drop-ddl-jdbc-file-name" value="dropDDL.sql"/>
<property name="toplink.application-location" value="/tmp"/>

I would like [my] JPA [provider] to check if the tables already exist and if not create them, however I could not find a value for the property above which does this.

Weird, according to the TopLink Essentials documentation about the toplink.ddl-generation extension, create-table should leave existing table unchanged:

TopLink JPA Extensions for Schema Generation

Specify what Data Descriptor Language (DDL) generation action you want for your JPA entities. To specify the DDL generation target, see toplink.ddl-generation.output-mode.

Valid values: oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider

If you are using persistence outside the EJB container and would like to create the DDL files without creating tables, additionally define a Java system property INTERACT_WITH_DB and set its value to false.

Liquibase (http://www.liquibase.org) is good at this. It takes some time to get fully used to it, but I think it's worth the effort.

The Liquibase-way is independent of which JPA persistence provider you use. Actually, it's even database agnostic.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!