-->
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: Deleting Many-To-Many Join Table associations
PostPosted: Fri Mar 06, 2009 7:50 pm 
Newbie

Joined: Fri Nov 21, 2008 3:35 pm
Posts: 12
I have two objects which are related through a many to many relationship, User and Group. I'm trying to delete the User from the database.

This is really easy to do if there is only one User in the Group's users list, I can simply delete the group object from the database. However, if there are more than one user in the group, deleting a User will not delete the row in my join table, causing errors when I try to fetch the group again, telling me that Hibernate couldn't locate the referenced User object. That makes sense, but how do I delete the m2m row?

Here's my setup:

Group:
@JoinTable (
name="m2m_group_members",
joinColumns=@JoinColumn(name="group_id"),
inverseJoinColumns=@JoinColumn(name="user_id")
)
private List<User> members;

User:
@ManyToMany(
mappedBy="members",
targetEntity=SupportGroup.class
)
private List<SupportGroup> groups;


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.