my dog learned polymorphism
The moose likes Object Relational Mapping and the fly likes hibernate many-to-many Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "hibernate many-to-many" Watch "hibernate many-to-many" New topic

hibernate many-to-many

Larry Jones

Joined: Jan 23, 2005
Posts: 7
how do you delete and update a many-to-many relationship in hibernate without deleting the two related objects from the db; that is, I just want to remove the entry in the many-to-many table that joins the two objects, not the two objects themselves.

Thanks for the help
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63865

Moved to ORM.

[Asking smart questions] [About Bear] [Books by Bear]
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
I haven't used many-to-many relationships with Hibernate yet, but I can make an educated guess.
  • Load one of the objects (A).
  • Find the other object (B) in A's collection of Bs.
  • Remove B from the collection.
  • Save A.

  • I don't think you'll need to do the same from the other side, or if it depends on whether or not it's an inverse association, or if N:N relations can even be inverse.
    I agree. Here's the link:
    subject: hibernate many-to-many
    It's not a secret anymore!