2015-12-22 25 views
1

我有一對多奇怪的行爲:不成功:改變表添加約束:表不存在上創建

ENTITY1:

@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"); 

它給出了fo在啓動llowing錯誤:

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 

我試圖下降,由數據庫中的所有表格中,成功創建的所有表(我有這種類型的其他實體的關係,這些表也被創建),除了這一個。我究竟做錯了什麼?謝謝。

+0

'Deal'(和'Entity1')類annoted用'@ Entity'? –

+0

@ redflar3是的,這兩個 –

+0

已經存在同名的表?然後嘗試刪除它們並運行該程序,或者使用'create-drop'代替'create'嘗試使用.. –

回答

1

最後我發現了什麼問題。 要命名我的字段,我使用了MySQL關鍵字:to,from,show。 因此,由Hibernate生成的SQL創建請求對於MySQL來說是完全無用的,唯一的標誌是來自服務器的語法錯誤的消息。 我通過逐個刪除字段並重新啓動,逐步找到它。