I have three tables/entities which are Event, Participant, and ParticipantEvent. ParticipantEvent is kind of like join table of many to many relationship but I have made it as an entity. And the mapping goes like this.
public class Event {
@OneToMany(mappedBy = "event", cascade=CascadeType.REMOVE)
private List<ParticipantEvent> participantEvents;
}
public class Participant {
@OneToMany(mappedBy = "participant", cascade=CascadeType.ALL)
private List<ParticipantEvent> participantEvents;
}
public class ParticipantEvent {
@ManyToOne
private Event event;
@ManyToOne
private Participant participant;
}
When I delete an event, hibernate does not trigger deletion of ParticipantEvent. It give foreign key constraint violation error until I give ParticipantEvent -> Participant cascade to ALL. This will triggers delete on ParticipantEvent fine, but also deletes data from Participant table as well yet I don't want to delete any data from Participant table.
I am lost here, I don't think ParticipantEvent DML should depend on Participant or Event.