• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

@ManyToMany remove records from join rows

 
Marcus Casey
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I remove a record from the join table in a many-to-many relationship?

I am using JPA. I have created a many-to-many relationship between users and groups. A MyUser can be in more than one MyGroup and a MyGroup can have more than one MyUser. Pretty straightforward.

Here is some of my code for MyUser:


and for MyGroup:


As you can tell from the code, I have a join table called my_user_group that just has the foreign keys from each table. (You may also notice it is unidirectional. I don't have a need to list the users by group, only the groups by user).

Now to my question--how do I remove a group from a user? I notice that if I remove a group from the List on my object and the perform a merge(), the foreign key records for the removed group are still there.

Any suggestions would be most welcome.
 
Mike Keith
author
Ranch Hand
Posts: 304
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marcus,

You are checking for the rows after committing the transaction, right? The rows won't typically be removed until commit-time. Maybe if you could post your code I could see what else could be going wrong. Your mappings look okay.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic