Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

@ManyToMany remove records from join rows

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.
Posts: 304
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
permaculture is a more symbiotic relationship with nature so I can be even lazier. Read tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic