Java Persistence API (JPA) Extensions Reference for EclipseLink, Release 2.4
  Go To Table Of Contents
 Search
 PDFComments
Comments


ddl-generation

Use eclipselink.ddl-generation to specify how EclipseLink generates DDL (Data Definition Language) for the database schema (tables and constraints) on deployment


Values

Table 5-29 describes this persistence property's values.

Table 5-29 Valid Values for ddl-generation

Value Description

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; the existing table will be used. EclipseLink will then continue with the next statement.

create-or-extend-tables

EclipseLink will attempt to create tables. If the table exists, EclipseLink will add any missing columns.

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

This is useful in development if the schema frequently changes or during testing when the existing data needs to be cleared.

Note: Using drop-and-create will remove all of the data in the tables when they are dropped. You should never use option on a production schema that has valuable data in the database. If the schema changed dramatically, there could be old constraints in the database that prevent the dropping of the old tables. This may require the old schema to be dropped through another mechanism

none

(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: