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;
|