Hello!
Hibernate 3.2.6, MySQL 5 IMAP
I got a many-to-many relation between a
Display and a
DisplayGroup. Each Display may be in several DisplayGroups.
Display.java
Code:
@ManyToMany(mappedBy="displays", targetEntity=DisplayGroup.class)
private List<DisplayGroup> displayGroups = new ArrayList<DisplayGroup>();
DisplayGroup.javaCode:
@ManyToMany(targetEntity = Display.class)
@JoinTable(name="px_rel_display_displaygroup",
joinColumns={@JoinColumn(name="dig_id", referencedColumnName="dig_id")},
inverseJoinColumns={@JoinColumn(name="dis_id", referencedColumnName="dis_id")})
private List<Display> displays = new ArrayList<Display>();
If a Display is deleted, I want that only the associations in the join table are deleted, not a DisplayGroup. And vice versa. Deletion of a Display or a DisplayGroup should not affect the other Entity.
However, when I delete a DisplayGroup, everything is fine, but when I try to delete a Display I get the following MySQL Exception:
Code:
Cannot delete or update a parent row: a foreign key constraint fails (`px/px_rel_display_displaygroup`, CONSTRAINT `FK63153A13BB4E4648` FOREIGN KEY (`dis_id`) REFERENCES `px_display` (`dis_id`))
As far as I can tell, this means that Hibernate does not delete the associations in the join table before trying to delete the Display.
I tried several Cascade options, but that did not help me either, because then the problem is, that when I delete a DisplayGroup, all Displays are deleted too.
Can someone help me?
Thanks!