【发布时间】:2015-12-16 17:53:02
【问题描述】:
我有
public class RelationObject {
@OneToMany(orphanRemoval = true, mappedBy = "relationObject")
private Set<RelationParticipant> participants = new HashSet<RelationParticipant>();
}
public class BusinessObject {
@OneToMany(orphanRemoval = true, mappedBy = "businessObject")
private Set<RelationParticipant> participants = new HashSet<RelationParticipant>();
}
和
public class RelationParticipant {
@ManyToOne
@JoinColumn(name = "ro_id", nullable = false)
private RelationObject relationObject;
@ManyToOne
@JoinColumn(name = "bo_id", nullable = false)
private BusinessObject businessObject;
}
我有一个 RelationParticipant 连接到一个 RelationObject (relobj) 和一个 BusinessObject。 现在我执行 em.remove(relobj),在提交或刷新时我得到一个完整性异常。或者有时我不会,这取决于。
根据 JPA 规范,“如果将删除操作应用于托管源实体,则删除操作将级联到关系目标”。但有时这不会发生。有时会。为什么?
【问题讨论】: