How to turn off hbm2ddl?


Java Problem Overview

I couldn't find a reference on how to switch hbm2ddl off.

Java Solutions

Solution 1 - Java

Just omitting defaults to Hibernate not doing anything. From the reference documentation:

> ### 1.1.4. Hibernate configuration > > The option turns on > automatic generation of database > schemas directly into the database. > This can also be turned off by removing the configuration option, > or redirected to a file with the help > of the SchemaExport Ant task.

Setting to none (undocumented) might generate a warning, such as: org.hibernate.cfg.SettingsFactory - Unrecognized value for "": none

Solution 2 - Java

You can switch it off by :

It's undocumented but priceless !

Solution 3 - Java

To get this one clear, one should look into the source of org.hibernate.cfg.SettingsFactory (you might see something else depending on the version used):

String autoSchemaExport = properties.getProperty( AvailableSettings.HBM2DDL_AUTO );
if ( "validate".equals(autoSchemaExport) ) {
	settings.setAutoValidateSchema( true );
else if ( "update".equals(autoSchemaExport) ) {
	settings.setAutoUpdateSchema( true );
else if ( "create".equals(autoSchemaExport) ) {
	settings.setAutoCreateSchema( true );
else if ( "create-drop".equals( autoSchemaExport ) ) {
	settings.setAutoCreateSchema( true );
	settings.setAutoDropSchema( true );
else if ( !StringHelper.isEmpty( autoSchemaExport ) ) {
	LOG.warn( "Unrecognized value for \"\": " + autoSchemaExport );

In the org.hibernate.cfg.Settings class those variables are initialized as:

private boolean autoCreateSchema;
private boolean autoDropSchema;
private boolean autoUpdateSchema;
private boolean autoValidateSchema;

so these default to false.

Omitting the setting should switch off the HBM2DDL_AUTO functionality as would suggested = none, but on the latter case you get a warning in the log.

Solution 4 - Java


Of course, the place to configure it depends on the way you configure your hibernate - if it is programatically, set the property there. If it is from hibernate.cfg.xml:

<property name="">validate</property>

Solution 5 - Java

If you enter an unsupported value it will tell you which ones are supported: o.h.b.i.SessionFactoryBuilderImpl : Unrecognized hbm2ddl_auto value : bla. Supported values include 'create', 'create-drop', 'update', 'none' and 'validate'. Ignoring

And the value none is the default, is officially supported and documented:

Solution 6 - Java

This property is not required. Just delete the entry completely from the xml file.


All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAlexView Question on Stackoverflow
Solution 1 - JavaPascal ThiventView Answer on Stackoverflow
Solution 2 - JavaJulien BRENELIEREView Answer on Stackoverflow
Solution 3 - JavaAndres SaaremõtsView Answer on Stackoverflow
Solution 4 - JavaBozhoView Answer on Stackoverflow
Solution 5 - JavajstadlerView Answer on Stackoverflow
Solution 6 - JavagdrtView Answer on Stackoverflow