在Play框架中!我定义了两个模型:
一方面,
@Entity
public class DashboardPosition extends Model {
public int orderId;
@ManyToOne(cascade=CascadeType.ALL)
public Dashboard dashboard;
}
而另一方面,
@Entity
public class Dashboard extends Model {
...
}
出于某种原因,当通过“dashboard.delete()”删除仪表板时,我收到以下日志的错误。
12:07:20,190 DEBUG ~ delete from Dashboard where id=?
12:07:20,204 WARN ~ SQL Error: 23003, SQLState: 23003
12:07:20,204 ERROR ~ Referential integrity constraint violation: "FKF7C253BD5A49DA96: PUBLIC.DASHBOARDPOSITION FOREIGN KEY(DASHBOARD_ID) REFERENCES PUBLIC.DASHBOARD(ID)"; SQL statement:
delete from Dashboard where id=? [23003-149]
12:07:20,204 WARN ~ SQL Error: 23003, SQLState: 23003
12:07:20,204 ERROR ~ Referential integrity constraint violation: "FKF7C253BD5A49DA96: PUBLIC.DASHBOARDPOSITION FOREIGN KEY(DASHBOARD_ID) REFERENCES PUBLIC.DASHBOARD(ID)"; SQL statement:
delete from Dashboard where id=? [23003-149]
这让我觉得cascade在我的情况下不起作用。 任何可能发生这种情况的原因/如何调试此问题?
答案 0 :(得分:4)
级联是关联的错误方面。
删除仪表板时,您希望删除所有仪表板的位置。但是,当您删除其中一个位置时,您不希望删除仪表板。因此,应在仪表板的@OneToMany
字段的positions
注释上设置级联。