Sun Java System Application Server Platform Edition 9 Developer's Guide

Generation Options

Schema generation properties or asadmin command line options can control automatic schema generation by the following:


Note –

Before using these options, make sure you have a properly configured database. See Specifying the Database.


The following optional schema generation properties control the automatic creation of database tables at deployment. You can specify them in the persistence.xml file.

Table 7–2 Schema Generation Properties

Property 

Default 

Description 

toplink.ddl-generation

none

Specifies whether tables and DDL files are created during deployment, and whether tables are dropped first if they already exist. Allowed values are create-tables, drop-and-create-tables, and none.

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.

toplink.create-ddl-jdbc-file-name

createDDL.jdbc

Specifies the name of the JDBC file that contains the DDL statements required to create the required objects (tables, sequences, and constraints) in the database. 

toplink.drop-ddl-jdbc-file-name

dropDDL.jdbc

Specifies the name of the JDBC file that contains the DDL statements required to drop the required objects (tables, sequences, and constraints) from the database. 

toplink.application-location

. for the current working directory

For persistence outside the EJB container, specifies the location where the DDL files are written. 

For persistence within the EJB container, if this property is set, the value is ignored, and DDL files are written to one of the following locations, for applications and modules, respectively: 

domain-dir/generated/ejb/j2ee-apps/app-name

domain-dir/generated/ejb/j2ee-modules/mod-name

toplink.ddl-generation.output-mode

both

Specifies the DDL generation target if you are in Java SE mode, outside the EJB container. Values are as follows: 

  • both – Generates SQL files and executes them on the database. If toplink.ddl-generation is set to create-tables, then toplink.create-ddl-jdbc-file-name is written to toplink.application-location and executed on the database. If toplink.ddl-generation is set to drop-and-create-tables, then both toplink.create-ddl-jdbc-file-name and toplink.drop-ddl-jdbc-file-name are written to toplink.application-location and both SQL files are executed on the database.

  • database – Executes SQL on the database only (does not generate SQL files). If toplink.ddl-generation is set to create-tables, then toplink.create-ddl-jdbc-file-name is executed on the database. It is not written to toplink.application-location. If toplink.ddl-generation is set to drop-and-create-tables, then both toplink.create-ddl-jdbc-file-name and toplink.drop-ddl-jdbc-file-name are executed on the database. Neither is written to toplink.application-location.

  • sql-script – Generates SQL files only (does not execute them on the database). If toplink.ddl-generation is set to create-tables, then toplink.create-ddl-jdbc-file-name is written to toplink.application-location. It is not executed on the database. If toplink.ddl-generation is set to drop-and-create-tables, then both toplink.create-ddl-jdbc-file-name and toplink.drop-ddl-jdbc-file-name are written to toplink.application-location. Neither is executed on the database.

The following options of the asadmin deploy or asadmin deploydir command control the automatic creation of database tables at deployment.

Table 7–3 The asadmin deploy and asadmin deploydir Generation Options

Option 

Default 

Description 

--createtables

none 

If true, causes database tables to be created for entities that need them. If false, does not create tables. If not specified, the value of the toplink.ddl-generation property in persistence.xml is used.

--dropandcreatetables

none 

If true, and if tables were automatically created when this application was last deployed, tables from the earlier deployment are dropped and fresh ones are created.

If true, and if tables were not automatically created when this application was last deployed, no attempt is made to drop any tables. If tables with the same names as those that would have been automatically created are found, the deployment proceeds, but a warning is thrown to indicate that tables could not be created.

If false, the toplink.ddl-generation property setting in persistence.xml is overridden.

The following options of the asadmin undeploy command control the automatic removal of database tables at undeployment.

Table 7–4 The asadmin undeploy Generation Options

Option 

Default 

Description 

--droptables

none 

If true, causes database tables that were automatically created when the entities were last deployed to be dropped when the entities are undeployed. If false, does not drop tables.

If not specified, tables are dropped only if the toplink.ddl-generation property setting in persistence.xml is drop-and-create-tables.

For more information about the asadmin deploy, asadmin deploydir, and asadmin undeploy commands, see the Sun Java System Application Server Platform Edition 9 Reference Manual.

If one or more entities in the persistence unit are mapped to existing database tables and you use any of the asadmin deploy or asadmin deploydir options, the asadmin deployment options take precedence.

When asadmin deployment options and persistence.xml options are both specified, the asadmin deployment options take precedence.

The asant tasks sun-appserv-deploy and sun-appserv-undeploy are equivalent to asadmin deploy and asadmin undeploy, respectively. These asant tasks also override the persistence.xml options. For details, see Chapter 3, The asant Utility.