Reputation: 2105
I have strange behavior with OneToMany:
Entity1:
@OneToMany(fetch = FetchType.LAZY, mappedBy = "entity1")
private Set<Deal> deals;
Deal:
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "entity1_id")
private Entity1 entity1;
Also I have:
properties.setProperty("hibernate.hbm2ddl.auto", "create");
It gives following error upon start:
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
I tried drop all tables from db, all tables are created successfully (I have this type of relationship in other entities, those tables are also created) except of this one. What am I doing wrong? Thanks.
Upvotes: 1
Views: 2746
Reputation: 2105
Finally I found what the problem was. To name my fields I used MySQL key words: to, from, show. So the SQL create request generated by Hibernate was complete gibberish for MySQL, and the only sign was the message from the server that the syntax was wrong. I found it by deleting fields each after other and restarting, step by step.
Upvotes: 2