Hibernate架构更新问题
我已将一个字符串字段添加到我的休眠持久类中,并重新启动了应用程序。它启动了 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
听起来不像是 Hibernate 的问题。如果您尝试手动运行,您会发现会遇到同样的问题。通过查看 MySQL 手册,我发现“errno: 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:
http://dev.mysql.com/doc/refman/5.5/en/innodb-foreign-key-constraints.html
还要确保引用列和引用列之间的 TABLE_COLLATION 相同...否则您也会收到该错误。
Also make sure that the TABLE_COLLATION between the referenced and referent columns are the same...otherwise you also get that error.
对我来说,通过将所有表引擎更改为 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