Use eclipselink.ddl-generation
to specify how EclipseLink generates DDL (Data Definition Language) for the database schema (tables and constraints) on deployment
Note: EclipseLink does not support mixing EclipseLink defined and JPA defined DDL generation properties. If the eclipselink.ddl-generation
property is specified, the javax.persistence.schema-generation.database.action
, javax.persistence.schema-generation.scripts.action
, and javax.persistence.sql-load-script-source
JPA defined properties will be ignored.
Values
Table 5-29 describes this persistence property's values.
Table 5-29 Valid Values for ddl-generation
Value | Description |
---|---|
|
EclipseLink will attempt to execute a If the table already exists, EclipseLink will follow the default behavior of your specific database and JDBC driver combination (when a |
|
EclipseLink will attempt to create tables. If the table exists, EclipseLink will add any missing columns. |
|
EclipseLink will attempt to This is useful in development if the schema frequently changes or during testing when the existing data needs to be cleared. Note: Using |
|
(Default) No DDL generated; no schema generated. |
Usage
You can use create-or-extend-tables
only when eclipselink.ddl-generation.output-mode
= database
.
If you are using persistence in a Java SE environment 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
.
Examples
Example 5-17 shows how to use this property in the persistence.xml
file.
Example 5-17 Using ddl-generation in persistence.xml
<property name="eclipselink.ddl-generation" value="drop-and-create-tables"/> <property name="eclipselink.create-ddl-jdbc-file-name" value="createDDL_ddlGeneration.jdbc"/> <property name="eclipselink.drop-ddl-jdbc-file-name" value="dropDDL_ddlGeneration.jdbc"/> <property name="eclipselink.ddl-generation.output-mode" value="both"/>
Example 5-18 shows how to use this property in a property map.
Example 5-18 Using ddl-generation in a Property Map
import org.eclipse.persistence.config.PersistenceUnitProperties; propertiesMap.put(PersistenceUnitProperties.DDL_GENERATION, PersistenceUnitProperties.DROP_AND_CREATE); propertiesMap.put(PersistenceUnitProperties.DDL_GENERATION_MODE, PersistenceUnitProperties.BOTH); propertiesMap.put(PersistenceUnitProperties.CREATE_JDBC_DDL_FILE, "create.sql");
See Also
For more information, see: