Eclipselink update existing tables

十年热恋 提交于 2019-12-02 22:06:27

As of EclipseLink 2.4, you can use this in the specification of your persistence unit:

<property name="eclipselink.ddl-generation" value="create-or-extend-tables" />

This is the expected behavior when using the create-tables value. From the documentation about the eclipselink.ddl-generation property:

Using EclipseLink JPA Extensions for Schema Generation

The following are the valid values for the use in a persistence.xml file:

  • none – EclipseLink does not generate DDL; no schema is generated.
  • create-tables – EclipseLink will attempt to execute a CREATE TABLE SQL for each table. If the table already exists, EclipseLink will follow the default behavior of your specific database and JDBC driver combination (when a CREATE TABLE SQL is issued for an already existing table). In most cases an exception is thrown and the table is not created. EclipseLink will then continue with the next statement. (See also eclipselink.create-ddl-jdbc-file-name.)
  • drop-and-create-tables – EclipseLink will attempt to DROP all tables, then CREATE all tables. If any issues are encountered, EclipseLink will follow the default behavior of your specific database and JDBC driver combination, then continue with the next statement. (See also eclipselink.create-ddl-jdbc-file-name and eclipselink.drop-ddl-jdbc-file-name.)

So you might want drop-and-create-tables instead.

joshua

Hibernate JPA implementation does exactly what you want. Here is the property that enables that behaviour:

property name="hibernate.hbm2ddl.auto" value="update"

create-or-extend-tables does the trick

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