Java Reference
In-Depth Information
Table
4-1
lists the different
persistence.xml
or
EntityManagerFactory
properties that are used to configure
schema generation. These properties are passed as a
Map
argument from the container to the
PersistenceProvider
generateSchema
method, or the
createContainerEntityManagerFactory
method. Each of the properties resides
within the
javax.persistence
package, and therefore, should be prefixed with
javax.persistence
.
Table 4-1.
Schema Generation Properties
Property
Purpose
schema-generation.create-script-source
Name of script that is packaged as part of application, or a string
corresponding to file URL string that designates a script.
schema-generation.drop-script-source
Name of script that is packaged as part of application, or a string
corresponding to file URL string that designates a script
sql-load-script-source
Name of script that is packaged as part of application, or a string
corresponding to file URL string that designates a script
schema-generation.database.action
Controls action to be taken by persistence provider with regard to
database access
Values
: “none,” “create,” “drop-and-create,” “drop”
schema-generation.scripts.action
Controls action to be taken by persistence provider with regard to script
generation
Values
: “none,” “create,” “drop-and-create,” “drop”
schema-generation.create-source
Specifies whether the creation of database artifacts should occur on the
basis of the ORM metadata, DDL script, or both
Values
: “metadata,” “script,” “metadata-then-script,” “script-then-metadata”
schema-generation.drop-source
Specifies whether the dropping of database artifacts should occur on
the basis of ORM metadata, DDL script, or both
Values
: “metadata,” “script,” “metadata-then-script,” “script-then-metadata”
schema-generation.scripts.create-target
When generating scripts, these properties specify the
schema-generation.scripts.drop-target
the target locations in String format.
The schema generation is controlled by utilization of the properties that are listed in Table
4-1
within the
persistence.xml
. The following example of
persistence.xml
demonstrates how to have database artifacts and
scripts generated for creation of both.
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="
http://java.sun.com/xml/ns/persistence
" xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance
"
xsi:schemaLocation="
http://java.sun.com/xml/ns/
<persistence-unit name="IntroToJavaEE7PU" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>jdbc/DerbyConnection</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<properties>
<property name="javax.persistence.schema-generation.database.action" value="create"/>
<property name="javax.persistence.schema-generation.scripts.action" value="create"/>