Hibernate hbm2ddl.auto 配置的可能值是什么,它们有什么作用 [英] What are the possible values of the Hibernate hbm2ddl.auto configuration and what do they do
问题描述
我真的很想知道更多关于更新、导出和可以给 hibernate.hbm2ddl.auto
的值我需要知道何时使用更新,何时不使用?还有什么选择?
I really want to know more about the update, export and the values that could be given to hibernate.hbm2ddl.auto
I need to know when to use the update and when not? And what is the alternative?
这些是可能发生在数据库上的变化:
These are changes that could happen over DB:
- 新表
- 旧表中的新列
- 已删除列
- 列的数据类型已更改
- 一种类型的列改变了它的属性
- 桌子掉了
- 列的值已更改
在每种情况下,最佳解决方案是什么?
In each case what is the best solution?
推荐答案
来自 社区文档:
hibernate.hbm2ddl.auto 在创建 SessionFactory 时自动验证或导出模式 DDL 到数据库.使用 create-drop,当 SessionFactory 显式关闭时,数据库架构将被删除.
hibernate.hbm2ddl.auto Automatically validates or exports schema DDL to the database when the SessionFactory is created. With create-drop, the database schema will be dropped when the SessionFactory is closed explicitly.
例如验证 |更新 |创建 |创建删除
e.g. validate | update | create | create-drop
所以可能的选项列表是,
So the list of possible options are,
- validate:验证架构,不对数据库做任何更改.
- update:更新架构.
- create:创建模式,销毁之前的数据.
- create-drop:在 SessionFactory 显式关闭时删除架构,通常是在应用程序停止时.
- none:对架构不做任何事情,不对数据库做任何更改
- validate: validate the schema, makes no changes to the database.
- update: update the schema.
- create: creates the schema, destroying previous data.
- create-drop: drop the schema when the SessionFactory is closed explicitly, typically when the application is stopped.
- none: does nothing with the schema, makes no changes to the database
这些选项似乎旨在成为开发人员的工具,而不是为任何生产级数据库提供便利,您可能需要查看以下问题;休眠:hbm2ddl.auto=生产中的更新?
These options seem intended to be developers tools and not to facilitate any production level databases, you may want to have a look at the following question; Hibernate: hbm2ddl.auto=update in production?
这篇关于Hibernate hbm2ddl.auto 配置的可能值是什么,它们有什么作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!