Hibernate 配置属性

在 hibernate.cfg.xml 中有相当多的 Hibernate 配置项,较详细的解释在官方的 Developer Guilde 的附录中可以查到,参考路径是:

hibernate-release-4.3.5.Final/documentation/devguide/en-US/html/apa.html

部分配置项的参考值见:

hibernate-release-4.3.5.Final/project/etc/hibernate.properties

这里重点记录在开发实践中碰到的一些属性:

hbm2dll.auto

【官方解释】

Validates or exports schema DDL to the database when the SessionFactory is created. With create-drop, the database schema is dropped when the SessionFactory is closed explicitly.

当创建 SessionFactory 时,是否根据映射文件自动建立数据库表。

【参数值含义】

* validate (?) 验证,不更新表结构。

* update 更新表结构

* create 创建时删除原先的。这个参数太厉害了,每次会将原先的表连数据删除,然后新建表。

* create-drop 使用时创建表,退出时(关闭 SessionFactory 时)删除刚建的表。

【示例】

<prop key="hibernate.hbm2ddl.auto">update</prop>

在生产环境中,一般用 update 的比较普遍。