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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "hibernate many-to-many" Watch "hibernate many-to-many" New topic
Author

hibernate many-to-many

Larry Jones
Greenhorn

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
Marshal

Joined: Jan 10, 2002
Posts: 60789
    
  65

Moved to ORM.


[Asking smart questions] [Bear's FrontMan] [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.
     
    It is sorta covered in the JavaRanch Style Guide.
     
    subject: hibernate many-to-many
     
    Similar Threads
    what is the difference between HttpSession and Hibernate Session?
    manay-to-many vs bi-directional relationships
    Mapping objects history wih Hibernate
    string constant pool from K&B book
    Hibernate:What 'criteria.add(Restrictions' should be added to remove getting the list of'empl_notes'