• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

@ManyToMany remove records from join rows

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 304
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic