Java 休眠 - hibernate.hbm2ddl.auto = 验证

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2695861/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 10:55:52  来源:igfitidea点击:

Hibernate - hibernate.hbm2ddl.auto = validate

javahibernateormhbm2ddl

提问by azp74

I am interested in how hibernate.hbm2ddl.auto=validate actually works and I am struggling to find comprehensive documentation.

我对 hibernate.hbm2ddl.auto=validate 的实际工作方式很感兴趣,我正在努力寻找全面的文档。

We've recently discovered production system was affected by http://opensource.atlassian.com/projects/hibernate/browse/HHH-3532(Hibernate matches foreign keys on name, rather than signature and so will recreate them for you) and hibernate.hbm2ddl.auto=update is being removed from our next release.

我们最近发现生产系统受到http://opensource.atlassian.com/projects/hibernate/browse/HHH-3532(Hibernate匹配名称上的外键,而不是签名,因此会为您重新创建它们)和 hibernate 的影响.hbm2ddl.auto=update 将从我们的下一个版本中删除。

I would be quite happy to just get rid of hibernate.hbm2ddl.auto altogether and manage our database ourselves. However, not all my colleagues share this world view and some are keen to add back in hibernate.hbm2ddl.auto=validate.

我很乐意完全摆脱 hibernate.hbm2ddl.auto 并自己管理我们的数据库。然而,并不是我所有的同事都认同这个世界观,有些人热衷于在 hibernate.hbm2ddl.auto=validate 中添加回来。

I'm concerned this will hit the same problem and I'm interested in finding more documentation about how this validation actually works. The Hibernate Community Documentation (http://docs.jboss.org/hibernate/core/3.3/reference/en/html/session-configuration.html) really just makes reference to the values.

我担心这会遇到同样的问题,我有兴趣找到更多有关此验证实际工作方式的文档。Hibernate 社区文档(http://docs.jboss.org/hibernate/core/3.3/reference/en/html/session-configuration.html)实际上只是引用了这些值。

Does anyone have any good documentation pointers, or any real life experience of using validate in a production system?

有没有人有任何好的文档指针,或者任何在生产系统中使用验证的实际经验?

采纳答案by Pascal Thivent

I'm concerned this will hit the same problem and I'm interested in finding more documentation about how this validation actually works.

我担心这会遇到同样的问题,我有兴趣找到更多有关此验证实际工作方式的文档。

In my opinion, the best documentation is the source code that you could check to see what is happening exactly. The relevant method is org.hibernate.tool.hbm2ddl.SchemaValidator#validate().

在我看来,最好的文档是源代码,您可以检查它以了解究竟发生了什么。相关方法是org.hibernate.tool.hbm2ddl.SchemaValidator#validate()

I went quickly through the code and Idon't think that the SchemaValidatorverifies foreign keys in the database: it checks the presence of tables, columns, id generators but not foreign keys. A test against a pet database seems to confirm this behavior: dropping a FK constraint doesn't break schema validation (in other words, the validator checks if the application can run, not for referential integrity).

我快速浏览了代码,不认为SchemaValidator验证数据库中的外键:它检查表、列、id 生成器的存在,但不检查外键。针对 pet 数据库的测试似乎证实了这种行为:删除 FK 约束不会破坏模式验证(换句话说,验证器检查应用程序是否可以运行,而不是为了参照完整性)。

Now, HHH-3532being marked as fixed, why don't you upgrade to a newer version of Hibernate or, if changing the version of Hibernate is too heavy, why don't you apply the patch for HHH-3532yourself?

现在,HHH-3532被标记为已修复,为什么不升级到更新版本的 Hibernate 或者,如果更改 Hibernate 版本太重,为什么不自己为HHH-3532应用补丁?

Having that all said, Idon't use hibernate.hbm2ddl.auto=updateto update production databases, I use change scripts. But Iuse hibernate.hbm2ddl.auto=validateand I'm happy with it.

说了这么多,不用hibernate.hbm2ddl.auto=update来更新生产数据库,我使用更改脚本。但使用它hibernate.hbm2ddl.auto=validate,我很满意。