我对 OneToMany 有奇怪的行为:
实体 1:
@OneToMany(fetch = FetchType.LAZY, mappedBy = "entity1")
private Set<Deal> deals;
交易:
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "entity1_id")
private Entity1 entity1;
我还有:
properties.setProperty("hibernate.hbm2ddl.auto", "create");
启动时出现如下错误:
ERROR: org.hibernate.tool.hbm2ddl.SchemaExport - HHH000389: Unsuccessful: alter table deal add constraint FK_d17qqf8ra0ibdsnngbp465qvs foreign key (entity1_id) references entity1 (entity1_id)
ERROR: org.hibernate.tool.hbm2ddl.SchemaExport - Table 'test.deal' doesn't exist
我尝试从 db 中删除所有表,所有表都已成功创建(我在其他实体中有这种类型的关系,这些表也已创建)除了这个。我究竟做错了什么?谢谢。
最佳答案
终于找到问题所在了。 为了命名我的字段,我使用了 MySQL 关键字:to、from、show。 因此,Hibernate 生成的 SQL 创建请求对于 MySQL 来说完全是乱码,唯一的标志是来自服务器的消息语法错误。 我通过逐个删除字段并重新启动来找到它。
关于java - 失败 : alter table add constraint: Table doesn't exist on create,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34409351/