Pas*_*ent 76
只是省略hibernate.hbm2ddl.auto了Hibernate的默认值而没有做任何事情.从参考文档:
1.1.4.Hibernate配置
该
hbm2ddl.auto选项可以直接将数据库模式自动生成到数据库中. 这也可以通过删除配置选项来关闭,或者在SchemaExport Ant任务的帮助下重定向到文件.
设置hbm2ddl.auto为none(未记录)可能会生成警告,例如:org.hibernate.cfg.SettingsFactory - Unrecognized value for "hibernate.hbm2ddl.auto": none
小智 35
您可以通过以下方式将其关闭:
hibernate.hbm2ddl.auto=none
Run Code Online (Sandbox Code Playgroud)
它没有证件但是无价!
小智 12
要明确这一点,应该查看源代码org.hibernate.cfg.SettingsFactory(根据使用的版本,您可能会看到其他内容):
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 );
}
Run Code Online (Sandbox Code Playgroud)
在org.hibernate.cfg.Settings类中,这些变量初始化为:
private boolean autoCreateSchema;
private boolean autoDropSchema;
private boolean autoUpdateSchema;
private boolean autoValidateSchema;
Run Code Online (Sandbox Code Playgroud)
所以这些默认为false.
省略hibernate.hbm2ddl.auto设置应该HBM2DDL_AUTO按照建议关闭功能hibernate.hbm2ddl.auto = none,但在后一种情况下,您会在日志中收到警告.
在hibernate.properties中
hibernate.hbm2ddl.auto=validate
Run Code Online (Sandbox Code Playgroud)
当然,配置它的位置取决于您配置休眠的方式-如果是编程方式,请在此处设置属性。如果来自hibernate.cfg.xml:
<property name="hibernate.hbm2ddl.auto">validate</property>
Run Code Online (Sandbox Code Playgroud)