我找不到关于如何关闭hbm2ddl的参考资料。
发布于 2010-07-05 21:44:00
只需省略hibernate.hbm2ddl.auto,默认情况下Hibernate什么也不做。参考文档中:
1.1.4. Hibernate configuration
hbm2ddl.auto选项启用将数据库模式直接自动生成到数据库中。Ant这也可以通过删除配置选项来关闭,或者在SchemaExport 任务的帮助下重定向到一个文件。
将hbm2ddl.auto设置为none (未记录)可能会生成警告,如:org.hibernate.cfg.SettingsFactory - Unrecognized value for "hibernate.hbm2ddl.auto": none
发布于 2013-04-04 19:54:45
您可以通过以下方式将其关闭:
hibernate.hbm2ddl.auto=none它是没有记录的,但却是无价的!
发布于 2014-10-15 20:26:44
要弄清楚这一点,应该查看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 );
}在org.hibernate.cfg.Settings类中,这些变量被初始化为:
private boolean autoCreateSchema;
private boolean autoDropSchema;
private boolean autoUpdateSchema;
private boolean autoValidateSchema;因此这些默认设置为false。
省略hibernate.hbm2ddl.auto设置应该会像建议的hibernate.hbm2ddl.auto = none那样关闭HBM2DDL_AUTO功能,但在后一种情况下,您会在日志中收到一条警告。
https://stackoverflow.com/questions/3179765
复制相似问题