Hibernate架构更新问题

发布于 2024-10-15 20:05:15 字数 591 浏览 4 评论 0原文

我已将一个字符串字段添加到我的休眠持久类中,并重新启动了应用程序。它启动了 SchemaUpgrade,并导致了几个错误,如下所示:

2011-02-03 13:04:06,522 [main] ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate - Unsuccessful: alter table table_name add index FKCD10932052C35B33 (previewExample_id), add constraint FKCD10932052C35B33 foreign key (previewExample_id) references preview (id)
2011-02-03 13:04:06,522 [main] ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate - Can't create table 'dbName.#sql-59c_1cc' (errno: 150)

该列已添加到数据库中。一切似乎都运转良好。除了每次启动应用程序时都会弹出的这些错误。

我可以做什么来帮助它创建这些索引? DB是MySQL,hibernate版本是3.0。

I've added a string field to my hibernate persistent class, and restarted the application. It started SchemaUpgrade, and resulted in several errors like this one:

2011-02-03 13:04:06,522 [main] ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate - Unsuccessful: alter table table_name add index FKCD10932052C35B33 (previewExample_id), add constraint FKCD10932052C35B33 foreign key (previewExample_id) references preview (id)
2011-02-03 13:04:06,522 [main] ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate - Can't create table 'dbName.#sql-59c_1cc' (errno: 150)

The column was added to the DB though. And everything seem to be working fine. Except fot those errors, popping out every time, I start the application.

What can I do to help it create those indexes? DB is MySQL, hibernate version is 3.0.

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

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

发布评论

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

评论(3

2024-10-22 20:05:15

听起来不像是 Hibernate 的问题。如果您尝试手动运行,您会发现会遇到同样的问题。通过查看 MySQL 手册,我发现“errno: 150”的含义是:

如果重新创建已删除的表,它必须具有符合引用它的外键约束的定义。如前所述,它必须具有正确的列名称和类型,并且必须在引用的键上具有索引。如果不满足这些条件,MySQL 将返回错误号 1005 并在错误消息中引用错误 150。

http://dev.mysql.com/doc /refman/5.5/en/innodb-foreign-key-constraints.html

It doesn't sounds like a Hibernate problem. If you try to run manually, you'll see that you'll get the same problem. By looking at MySQL manuals, I see that "errno: 150" means:

If you re-create a table that was dropped, it must have a definition that conforms to the foreign key constraints referencing it. It must have the right column names and types, and it must have indexes on the referenced keys, as stated earlier. If these are not satisfied, MySQL returns error number 1005 and refers to error 150 in the error message.

http://dev.mysql.com/doc/refman/5.5/en/innodb-foreign-key-constraints.html

许你一世情深 2024-10-22 20:05:15

还要确保引用列和引用列之间的 TABLE_COLLATION 相同...否则您也会收到该错误。

Also make sure that the TABLE_COLLATION between the referenced and referent columns are the same...otherwise you also get that error.

手心的温暖 2024-10-22 20:05:15

对我来说,通过将所有表引擎更改为 InnoDB 解决了问题。

以下是手动执行此操作的方法:

https://stackoverflow.com/a/9492183/1988704

For me the problem was resolved by changing all the tables Engine to InnoDB.

Here is how to do it manually :

https://stackoverflow.com/a/9492183/1988704

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