Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何删除具有一对多关系的实体?_Java_Spring_Hibernate - Fatal编程技术网

Java 如何删除具有一对多关系的实体?

Java 如何删除具有一对多关系的实体?,java,spring,hibernate,Java,Spring,Hibernate,我的班级建设包括: @JsonBackReference @OneToMany(cascade = CascadeType.MERGE, orphanRemoval = true, fetch = FetchType.LAZY, mappedBy = "building") private List<Floor> floorList = new ArrayList<>(); 现在我根本无法删除建筑,当我尝试删除BYID(id)时,出现了以下错误: o

我的班级建设包括:

@JsonBackReference
@OneToMany(cascade = CascadeType.MERGE, orphanRemoval = true, fetch = FetchType.LAZY, mappedBy = "building")
private List<Floor> floorList = new ArrayList<>();
现在我根本无法删除建筑,当我尝试删除BYID(id)时,出现了以下错误:

org.h2.jdbc.JdbcSQLIntegrityConstraintViolationException: Naruszenie więzów integralności: "FKNRVYGRFI0C51V0GF7JI9KF4QK: PUBLIC.ASSET FOREIGN KEY(FLOOR_ID) REFERENCES PUBLIC.FLOOR(ID) (129)"
Referential integrity constraint violation: "FKNRVYGRFI0C51V0GF7JI9KF4QK: PUBLIC.ASSET FOREIGN KEY(FLOOR_ID) REFERENCES PUBLIC.FLOOR(ID) (129)"; SQL statement:
delete from floor where id=? [23503-200]

我已经尝试过cascade=CascadeType.ALL、MERGE、REMOVE和without-cascade,但没有任何效果。删除建筑的唯一方法是首先删除所有楼层(floorList为空)。

该错误与
建筑
-
楼层
关联无关,Hibernate实际上正试图从
楼层
表中删除,正如日志告诉您的那样。还有另一个表
ASSET
,该表中的一行通过
floor\u id
列引用要删除的
floor
行之一。您可以从错误消息中读取所有信息错误与
建筑
-
楼层
关联无关,Hibernate实际上正试图
楼层
表中删除,日志告诉您。还有另一个表
ASSET
,该表中的一行通过
floor\u id
列引用要删除的
floor
行之一。您可以从错误消息中读取所有内容
org.h2.jdbc.JdbcSQLIntegrityConstraintViolationException: Naruszenie więzów integralności: "FKNRVYGRFI0C51V0GF7JI9KF4QK: PUBLIC.ASSET FOREIGN KEY(FLOOR_ID) REFERENCES PUBLIC.FLOOR(ID) (129)"
Referential integrity constraint violation: "FKNRVYGRFI0C51V0GF7JI9KF4QK: PUBLIC.ASSET FOREIGN KEY(FLOOR_ID) REFERENCES PUBLIC.FLOOR(ID) (129)"; SQL statement:
delete from floor where id=? [23503-200]