0

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.

Mani Rai
  • 665
  • 2
  • 9
  • 22
  • tried just now but still foreign key constraint violation error. The thing is I have to declare participant relation cascade to all in participantevent entity in order to work event remove cascade. I don't know why should i need to declare participant relaction cascade to all. – Mani Rai Feb 06 '15 at 14:24
  • Firstly, you have mappedBy="event" while the field is named 'events'. Is this just a typo? Secondly, what version of Hibernate are you using? – Alan Hay Feb 06 '15 at 14:25
  • @AlanHay I am using hibernate 4.3.7 final version and it was mistake only in my question. – Mani Rai Feb 06 '15 at 14:31
  • @Goldbones: I have already tried that one. Still foreign key constraint error occurs. – Mani Rai Feb 06 '15 at 14:33
  • @Goldbones: Sorry for being offline... I had an internet broke down for an hour. can we do it again? – Mani Rai Feb 06 '15 at 16:31

0 Answers0