Hibernate - hibernate.hbm2ddl.auto = 验证

发布于 2024-08-30 03:31:26 字数 782 浏览 6 评论 0原文

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

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

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

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

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

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

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.

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.

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.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

美人迟暮 2024-09-06 03:31:26

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

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

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

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

话虽如此,我不使用 hibernate.hbm2ddl.auto=update 来更新生产数据库,而是使用更改脚本。但是使用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.

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().

I went quickly through the code and I don't think that the SchemaValidator verifies 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).

Now, HHH-3532 being 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-3532 yourself?

Having that all said, I don't use hibernate.hbm2ddl.auto=update to update production databases, I use change scripts. But I use hibernate.hbm2ddl.auto=validate and I'm happy with it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文