How to turn off hbm2ddl?
Just omitting hibernate.hbm2ddl.auto
defaults to Hibernate not doing anything. From the reference documentation:
1.1.4. Hibernate configuration
The
hbm2ddl.auto
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 hbm2ddl.auto
to none
(undocumented) might generate a warning, such as: org.hibernate.cfg.SettingsFactory - Unrecognized value for "hibernate.hbm2ddl.auto": none
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 \"hibernate.hbm2ddl.auto\": " + 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 hibernate.hbm2ddl.auto
setting should switch off the HBM2DDL_AUTO
functionality as would suggested hibernate.hbm2ddl.auto = none
, but on the latter case you get a warning in the log.