These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Removing relationship between many-to-many objects?
PostPosted: Thu Nov 15, 2007 12:57 am 
Newbie

Joined: Tue Aug 28, 2007 10:01 pm
Posts: 3
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.2

Mapping documents:
Code:
      <set name="relatedFromListNodes" table="RELATED_LISTNODE"
         inverse="true" cascade="save-update,remove,delete" lazy="extra">
         <key column="to_listnode_id" not-null="true"/>
         <many-to-many class="ListNode" column="from_listnode_id"/>
      </set>

      <set name="relatedToListNodes" table="RELATED_LISTNODE"
         inverse="false" cascade="save-update,remove,delete" lazy="extra">
         <key column="from_listnode_id" not-null="true"/>
         <many-to-many class="ListNode" column="to_listnode_id" />
      </set>



Code between sessionFactory.openSession() and session.close():
Code:
      list.getRelatedFromListNodes().clear();
      list.getRelatedToListNodes().clear();


Name and version of the database you are using:
MySQL 5.0

The generated SQL (show_sql=true):
There is no "update" sql

A ListNode object has relations with other ListNode objects.
I use many-to-many relation and use RELATED_LISTNODE table.

but when I want to remove all the relations of some ListNode object, it does not work.
I just want to remove "RELATIONSHIP between objects", not to delete the orther objects.

How can I do that? I couldn't find any solutions.

Thankds


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 15, 2007 7:51 am 
Expert
Expert

Joined: Fri Jul 13, 2007 8:18 am
Posts: 370
Location: london
Clearing the collections will only remove entries from the non-inverse mapping i.e. relatedToListNodes. Were there definitely entries in the relatedTo collection?

Because the relationship is bi-directional you should implement methods in the ListNode class to properly update the relationships. Calling clear() on the collections leaves the data in an inconsistent state - node A might no longer point TO node B but node B would still point FROM node A.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.