23.14. Automatic schema generation
<table class="tableblock frame-all grid-all spread">
<colgroup>
<col style="width: 20%;">
<col style="width: 20%;">
<col style="width: 60%;">
</colgroup>
<tbody>
<tr>
<td class="tableblock halign-left valign-top">
Property
</td>
<td class="tableblock halign-left valign-top">
Example
</td>
<td class="tableblock halign-left valign-top">
Purpose
</td>
</tr>
<tr>
<td class="tableblock halign-left valign-top">
`hibernate.hbm2ddl.auto`
</td>
<td class="tableblock halign-left valign-top">
`none` (default value), `create-only`, `drop`, `create`, `create-drop`, `validate`, and `update`
</td>
<td class="tableblock halign-left valign-top"><div><div class="paragraph">
Setting to perform `SchemaManagementTool` actions automatically as part of the `SessionFactory` lifecycle.
Valid options are defined by the `externalHbm2ddlName` value of the [`Action`](https://docs.jboss.org/hibernate/orm/5.2/javadocs/org/hibernate/tool/schema/Action.html) enum:
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">`none`</dt>
<dd>
No action will be performed.
</dd>
<dt class="hdlist1">`create-only`</dt>
<dd>
Database creation will be generated.
</dd>
<dt class="hdlist1">`drop`</dt>
<dd>
Database dropping will be generated.
</dd>
<dt class="hdlist1">`create`</dt>
<dd>
Database dropping will be generated followed by database creation.
</dd>
<dt class="hdlist1">`create-drop`</dt>
<dd>
Drop the schema and recreate it on SessionFactory startup. Additionally, drop the schema on SessionFactory shutdown.
</dd>
<dt class="hdlist1">`validate`</dt>
<dd>
Validate the database schema
</dd>
<dt class="hdlist1">`update`</dt>
<dd>
Update the database schema
</dd>
</dl>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top">
`javax.persistence.schema-generation.database.action`
</td>
<td class="tableblock halign-left valign-top">
`none` (default value), `create-only`, `drop`, `create`, `create-drop`, `validate`, and `update`
</td>
<td class="tableblock halign-left valign-top"><div><div class="paragraph">
Setting to perform `SchemaManagementTool` actions automatically as part of the `SessionFactory` lifecycle.
Valid options are defined by the `externalJpaName` value of the [`Action`](https://docs.jboss.org/hibernate/orm/5.2/javadocs/org/hibernate/tool/schema/Action.html) enum:
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">`none`</dt>
<dd>
No action will be performed.
</dd>
<dt class="hdlist1">`create`</dt>
<dd>
Database creation will be generated.
</dd>
<dt class="hdlist1">`drop`</dt>
<dd>
Database dropping will be generated.
</dd>
<dt class="hdlist1">`drop-and-create`</dt>
<dd>
Database dropping will be generated followed by database creation.
</dd>
</dl>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top">
`javax.persistence.schema-generation.scripts.action`
</td>
<td class="tableblock halign-left valign-top">
`none` (default value), `create-only`, `drop`, `create`, `create-drop`, `validate`, and `update`
</td>
<td class="tableblock halign-left valign-top"><div><div class="paragraph">
Setting to perform `SchemaManagementTool` actions writing the commands into a DDL script file.
Valid options are defined by the `externalJpaName` value of the [`Action`](https://docs.jboss.org/hibernate/orm/5.2/javadocs/org/hibernate/tool/schema/Action.html) enum:
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">`none`</dt>
<dd>
No action will be performed.
</dd>
<dt class="hdlist1">`create`</dt>
<dd>
Database creation will be generated.
</dd>
<dt class="hdlist1">`drop`</dt>
<dd>
Database dropping will be generated.
</dd>
<dt class="hdlist1">`drop-and-create`</dt>
<dd>
Database dropping will be generated followed by database creation.
</dd>
</dl>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top">
`javax.persistence.schema-generation-connection`
</td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top">
Allows passing a specific `java.sql.Connection` instance to be used by `SchemaManagementTool`
</td>
</tr>
<tr>
<td class="tableblock halign-left valign-top">
`javax.persistence.database-product-name`
</td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top">
Specifies the name of the database provider in cases where a Connection to the underlying database is not available (aka, mainly in generating scripts).
In such cases, a value for this setting _must_ be specified.
The value of this setting is expected to match the value returned by `java.sql.DatabaseMetaData#getDatabaseProductName()` for the target database.
Additionally, specifying `javax.persistence.database-major-version` and/or `javax.persistence.database-minor-version` may be required to understand exactly how to generate the required schema commands.
</td>
</tr>
<tr>
<td class="tableblock halign-left valign-top">
`javax.persistence.database-major-version`
</td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top">
Specifies the major version of the underlying database, as would be returned by `java.sql.DatabaseMetaData#getDatabaseMajorVersion` for the target database.
This value is used to help more precisely determine how to perform schema generation tasks for the underlying database in cases where `javax.persistence.database-product-name` does not provide enough distinction.
</td>
</tr>
<tr>
<td class="tableblock halign-left valign-top">
`javax.persistence.database-minor-version`
</td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top">
Specifies the minor version of the underlying database, as would be returned by `java.sql.DatabaseMetaData#getDatabaseMinorVersion` for the target database.
This value is used to help more precisely determine how to perform schema generation tasks for the underlying database in cases where `javax.persistence.database-product-name` and `javax.persistence.database-major-version` does not provide enough distinction.
</td>
</tr>
<tr>
<td class="tableblock halign-left valign-top">
`javax.persistence.schema-generation.create-source`
</td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"><div><div class="paragraph">
Specifies whether schema generation commands for schema creation are to be determine based on object/relational mapping metadata, DDL scripts, or a combination of the two.
See [`SourceType`](https://docs.jboss.org/hibernate/orm/5.2/javadocs/org/hibernate/tool/schema/SourceType.html) for valid set of values.
</div>
<div class="paragraph">
If no value is specified, a default is assumed as follows:
</div>
<div class="ulist">
- if source scripts are specified (per
javax.persistence.schema-generation.create-script-source
), thenscripts
is assumed otherwise,
metadata
is assumed </div></div></td> </tr>javax.persistence.schema-generation.drop-source
</td>Specifies whether schema generation commands for schema dropping are to be determine based on object/relational mapping metadata, DDL scripts, or a combination of the two. See
SourceType
for valid set of values.</div>
If no value is specified, a default is assumed as follows:
</div>
if source scripts are specified (per
javax.persistence.schema-generation.create-script-source
), thenscripts
is assumedotherwise,
metadata
is assumed </div></div></td> </tr>javax.persistence.schema-generation.create-script-source
</td>Specifies the
create
script file as either ajava.io.Reader
configured for reading of the DDL script file or a string designating a filejava.net.URL
for the DDL script.Hibernate historically also accepted
hibernate.hbm2ddl.import_files
for a similar purpose, butjavax.persistence.schema-generation.create-script-source
should be preferred overhibernate.hbm2ddl.import_files
. </td> </tr>javax.persistence.schema-generation.drop-script-source
</td>Specifies the
drop
script file as either ajava.io.Reader
configured for reading of the DDL script file or a string designating a filejava.net.URL
for the DDL script. </td> </tr>javax.persistence.schema-generation.scripts.create-target
</td>For cases where the
javax.persistence.schema-generation.scripts.action
value indicates that schema creation commands should be written to DDL script file,javax.persistence.schema-generation.scripts.create-target
specifies either ajava.io.Writer
configured for output of the DDL script or a string specifying the file URL for the DDL script. </td> </tr>javax.persistence.schema-generation.scripts.drop-target
</td>For cases where the
javax.persistence.schema-generation.scripts.action
value indicates that schema dropping commands should be written to DDL script file,javax.persistence.schema-generation.scripts.drop-target
specifies either ajava.io.Writer
configured for output of the DDL script or a string specifying the file URL for the DDL script. </td> </tr>javax.persistence.hibernate.hbm2ddl.import_files
</td>import.sql
(default value) </td>Comma-separated names of the optional files containing SQL DML statements executed during the
SessionFactory
creation. File order matters, the statements of a give file are executed before the statements of the following one.</div>
These statements are only executed if the schema is created, meaning that
hibernate.hbm2ddl.auto
is set tocreate
,create-drop
, orupdate
.javax.persistence.schema-generation.create-script-source
/javax.persistence.schema-generation.drop-script-source
should be preferred.</div></div></td> </tr>
javax.persistence.sql-load-script-source
</td>JPA variant of
hibernate.hbm2ddl.import_files
. Specifies ajava.io.Reader
configured for reading of the SQL load script or a string designating the filejava.net.URL
for the SQL load script. A "SQL load script" is a script that performs some database initialization (INSERT, etc). </td> </tr>hibernate.hbm2ddl.import_files_sql_extractor
</td>Reference to the
ImportSqlCommandExtractor
implementation class to use for parsing source/import files as defined byjavax.persistence.schema-generation.create-script-source
,javax.persistence.schema-generation.drop-script-source
orhibernate.hbm2ddl.import_files
.Reference may refer to an instance, a Class implementing
ImportSqlCommandExtractor
of the fully-qualified name of theImportSqlCommandExtractor
implementation. If the fully-qualified name is given, the implementation must provide a no-arg constructor.The default value is
SingleLineSqlCommandExtractor
. </td> </tr>hibernate.hbm2dll.create_namespaces
</td>true
orfalse
(default value) </td>Specifies whether to automatically create also the database schema/catalog. </td> </tr>
javax.persistence.create-database-schemas
</td>true
orfalse
(default value) </td>The JPA variant of
hibernate.hbm2dll.create_namespaces
. Specifies whether the persistence provider is to create the database schema(s) in addition to creating database objects (tables, sequences, constraints, etc). The value of this boolean property should be set totrue
if the persistence provider is to create schemas in the database or to generate DDL that contains "CREATE SCHEMA" commands. If this property is not supplied (or is explicitlyfalse
), the provider should not attempt to create database schemas. </td> </tr>hibernate.hbm2ddl.schema_filter_provider
</td>Used to specify the
SchemaFilterProvider
to be used bycreate
,drop
,migrate
, andvalidate
operations on the database schema.SchemaFilterProvider
provides filters that can be used to limit the scope of these operations to specific namespaces, tables and sequences. All objects are included by default. </td> </tr>hibernate.hbm2ddl.jdbc_metadata_extraction_strategy
</td>grouped
(default value) orindividually
</td>Setting to choose the strategy used to access the JDBC Metadata. Valid options are defined by the
strategy
value of theJdbcMetadaAccessStrategy
enum:</div>
- `grouped`
SchemaMigrator
andSchemaValidator
execute a singlejava.sql.DatabaseMetaData#getTables(String, String, String, String[])
call to retrieve all the database table in order to determine if all thejavax.persistence.Entity
have a corresponding mapped database tables.</dd>
- `individually`
SchemaMigrator
andSchemaValidator
execute onejava.sql.DatabaseMetaData#getTables(String, String, String, String[])
call for eachjavax.persistence.Entity
in order to determine if a corresponding database table exists.</dd> </dl> </div></div></td> </tr>
hibernate.hbm2ddl.delimiter
</td>;
</td>Identifies the delimiter to use to separate schema management statements in script outputs. </td> </tr>
hibernate.schema_management_tool
</td>A schema name </td>
Used to specify the
SchemaManagementTool
to use for performing schema management. The default is to useHibernateSchemaManagementTool
</td> </tr>hibernate.synonyms
</td>true
orfalse
(default value) </td>If enabled, allows schema update and validation to support synonyms. Due to the possibility that this would return duplicate tables (especially in Oracle), this is disabled by default. </td> </tr>
hibernate.hbm2dll.extra_physical_table_types
</td>BASE TABLE
</td>Identifies a comma-separated list of values to specify extra table types, other than the default
TABLE
value, to recognize as defining a physical table by schema update, creation and validation. </td> </tr>hibernate.schema_update.unique_constraint_strategy
</td>DROP_RECREATE_QUIETLY
,RECREATE_QUIETLY
,SKIP
</td>Unique columns and unique keys both use unique constraints in most dialects.
SchemaUpdate
needs to create these constraints, but DBs support for finding existing constraints is extremely inconsistent. Further, non-explicitly-named unique constraints use randomly generated characters.</div>
Therefore, the
UniqueConstraintSchemaUpdateStrategy
offers the following options:</div>
- `DROP_RECREATE_QUIETLY`
Default option. Attempt to drop, then (re-)create each unique constraint. Ignore any exceptions being thrown.
</dd>
- `RECREATE_QUIETLY`
Attempts to (re-)create unique constraints, ignoring exceptions thrown if the constraint already existed
</dd>
- `SKIP`
Does not attempt to create unique constraints on a schema update.
</dd> </dl> </div></div></td> </tr>
hibernate.hbm2ddl.charset_name
</td>Charset.defaultCharset()
</td>Defines the charset (encoding) used for all input/output schema generation resources. By default, Hibernate uses the default charset given by
Charset.defaultCharset()
. This configuration property allows you to override the default JVM setting so that you can specify which encoding is used when reading and writing schema generation resources (e.g. File, URL). </td> </tr>hibernate.hbm2ddl.halt_on_error
</td>true
orfalse
(default value) </td>Whether the schema migration tool should halt on error, therefore terminating the bootstrap process. By default, the
EntityManagerFactory
orSessionFactory
are created even if the schema migration throws exceptions. To prevent this default behavior, set this property value totrue
. </td> </tr> </tbody> </table> </div>