如本文所述,
remove实体状态转换应从父级到子级联,而不是相反。
您需要这样的东西:
class Parent { String name; @oneToMany(mappedBy = "parent", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) List<Child> children = new ArrayList<>(); public void addChild(Child child) { child.setParent(this); children.add(child); } public void removeChild(Child child) { children.remove(child); child.setParent(null); }}class Child { String name; @ManyToOne Parent parent; @oneToOne(mappedBy = "child", cascade = CascadeType.ALL, orphanRemoval = true) Toy toy;}class Toy { String name; @oneToOne Child child;}


