I have
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>();
}
and
public class RelationParticipant {
@ManyToOne
@JoinColumn(name = "ro_id", nullable = false)
private RelationObject relationObject;
@ManyToOne
@JoinColumn(name = "bo_id", nullable = false)
private BusinessObject businessObject;
}
And I have a RelationParticipant connected to one RelationObject (relobj) and one BusinessObject. Now I do em.remove(relobj), and on commit or flush I get an integrity exception. Or sometimes I don't, it depends.
According to JPA spec, "If the remove operation is applied to a managed source entity, the remove operation will be cascaded to the relationship target". But sometimes that just does not happen. And sometimes does. Why?