-->
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.  [ 1 post ] 
Author Message
 Post subject: many-to-many: parent deleted when there is a child
PostPosted: Fri Aug 05, 2011 2:23 am 
Newbie

Joined: Fri Aug 05, 2011 1:36 am
Posts: 1
Hello everyone,

I have a many-to-many relationship where two records on one side have the same parent (the owner of the relationship) on the other side. When I delete one of the two records the parent and jointable records are also deleted. I don't want this. I expect that the parent will not be removed as long as there is a child on the other side.

I have the following data:

Code:
Table A                                     
SID | NAME                                 
-----------------------               
90  | xyz                                     
-----------------------               
91  | abc                                 

Table AB                                   
A_SID | B_SID
-----------------------               
90     | 5                                     
-----------------------               
91     | 5                             

Table B                                   
SID | NAME
-----------------------               
5    | lala                                                         


And this is the hibernate mapping

Code:
mapping of class A on table A:
<hibernate-mapping ...

        <set name="setOfBs" table="AB" inverse="true" cascade="delete-orphan">
            <key column="A_SID" not-null="true" />
            <many-to-many column="B_SID" class="B"/>
        </set>
...
</hibernate-mapping>

mapping of class B on table B:
<hibernate-mapping ...

        <set name="setOfAs" table="AB" lazy="false">
            <key column="B_SID" not-null="true" />
            <many-to-many column="A_SID" class="A"/>
        </set>
...
</hibernate-mapping>


After I delete the object with SID '90' and NAME 'xyz' my data looks like this:

Code:
05/08/2011 07:29:43,259 [DEBUG] SQL - delete from AB where B_SID=?
05/08/2011 07:29:43,259 [TRACE] BasicBinder - binding parameter [1] as [BIGINT] - 5
05/08/2011 07:29:43,264 [DEBUG] SQL - delete from B where SID=? and OBJECT_VERSIE=?
05/08/2011 07:29:43,265 [TRACE] BasicBinder - binding parameter [1] as [BIGINT] - 5
05/08/2011 07:29:43,265 [TRACE] BasicBinder - binding parameter [2] as [BIGINT] - 0
05/08/2011 07:29:43,275 [DEBUG] SQL - delete from A where SID=? and OBJECT_VERSIE=?
05/08/2011 07:29:43,275 [TRACE] BasicBinder - binding parameter [1] as [BIGINT] - 90
05/08/2011 07:29:43,275 [TRACE] BasicBinder - binding parameter [2] as [BIGINT] - 0


Code:
Table A                                     
SID | NAME                                 
-----------------------                           
91  | abc                                 

Table AB                                   
A_SID | B_SID
-----------------------                                   

Table B                                   
SID | NAME
-----------------------               


I would expect that the record in table B will not be removed because it's not an orphan. What am I doing wrong?


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

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.