-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Many-To-Many: Deletion of association
PostPosted: Sat Oct 04, 2008 6:45 am 
Newbie

Joined: Fri May 25, 2007 4:37 am
Posts: 13
Location: Germany
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.java
Code:
@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!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.