【发布时间】:2012-05-24 21:14:09
【问题描述】:
什么是默认值
hibernate.hbm2ddl.auto
在hibernate cfg文件映射中
是否可以删除
<property name="hibernate.hbm2ddl.auto">update</property>
这个来自配置文件的映射
如果我删除此属性是否会影响我的数据库
???
【问题讨论】:
标签: java mysql database hibernate
什么是默认值
hibernate.hbm2ddl.auto
在hibernate cfg文件映射中
是否可以删除
<property name="hibernate.hbm2ddl.auto">update</property>
这个来自配置文件的映射
如果我删除此属性是否会影响我的数据库
???
【问题讨论】:
标签: java mysql database hibernate
只是省略 hibernate.hbm2ddl.auto 默认 Hibernate 不做任何事情。
已经在 SO 中询问过。 link
【讨论】:
在创建 SessionFactory 时自动验证模式 DDL 或将其导出到数据库。使用 create-drop,当 SessionFactory 显式关闭时,数据库模式将被删除。
validate | update | create | create-drop
【讨论】:
Validate 是hibernate.hbm2ddl.auto 的默认值
Validate 不是默认值 - 如果您不指定值,则不会发生任何事情(甚至没有验证)。
这就是答案:no 验证,no 更新,no 创建和 no 丢弃发生从配置中省略设置时。 hibernate 源代码是关于 Hibernate 的最佳文档:
// from org.hibernate.cfg.SettingsFactory line 332 (hibernate-core-3.6.7)
String autoSchemaExport = properties.getProperty(Environment.HBM2DDL_AUTO);
if ( "validate".equals(autoSchemaExport) ) settings.setAutoValidateSchema(true);
if ( "update".equals(autoSchemaExport) ) settings.setAutoUpdateSchema(true);
if ( "create".equals(autoSchemaExport) ) settings.setAutoCreateSchema(true);
if ( "create-drop".equals(autoSchemaExport) ) {
settings.setAutoCreateSchema(true);
settings.setAutoDropSchema(true);
}
【讨论】: