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.
posted 8 years ago
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.