级联删除我的父实体时遇到问题:
org.postgresql.util.PSQLException:表“child”上的 UPDATE 或 DELETE 违反约束“XXX”:对于键 (id)=(4),表“child_properties”中有引用
@Entity
@Table(name = "Parent")
public class Parent{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@OneToMany(fetch = FetchType.EAGER,mappedBy = "parent")
@OnDelete(action = OnDeleteAction.CASCADE)
private Set<Child> children;
}
@Entity
@Table(name = "child")
public class Child{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne
@JoinColumn(name = "parent_id")
private Parent parent;
@ElementCollection(fetch = FetchType.EAGER)
private Map<String,String> properties;
}
我希望孩子删除它在 parentRepository.delete(parent) 上的属性,但这只会发生在 childRepository.delete(child) 上。父删除抛出异常