-->
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: One-shot delete on bi-directional many-to-many associations
PostPosted: Tue Jun 27, 2006 5:04 am 
Newbie

Joined: Mon Jun 26, 2006 8:51 am
Posts: 2
Hi,

As the subject says, I have a bi-directional many-to-many family/model relationship, mapped as cascade="all,delete-orphan" on the family side and inverse="true" on the model side. When I delete a family instance, Hibernate deletes all models attached to this family even models which are attached to others families.

Let's take an example :
family f1 with models m1,m2,m3 attached,
family f2 with models m1,m4 attached

The behaviour I expect is when I delete f1, I would like that Hibernate deletes f1 from the family table, all "links" related to f1 in the join table and all models which are attached to f1 AND NOT attached to others families. So, with my example, I would like that Hibernate deletes only m2 and m3 when I delete f1 (m1 is attached to f2 also!).

my mappings :

Code:
<class name="Family" table="family">
   <id name="uid">
      <column name="fam_kuid" />
      <generator class="sequence">
         <param name="sequence">seq_family</param>
      </generator>
   </id>
   
   <property name="name" column="fam_name" unique="true"/>

   <set name="models" table="family_model" cascade="all,delete-orphan">
      <key column="fam_kuid"/>
      <many-to-many column="mod_kuid" class="Model"/>
   </set>
</class>

<class name="Model" table="model">
   <id name="uid">
      <column name="mod_kuid" />
      <generator class="sequence">
         <param name="sequence">seq_model</param>
      </generator>
   </id>
   <property name="name" column="mod_name" />
   
   <set name="families" table="family_model" inverse="true" >
      <key column="mod_kuid"/>
      <many-to-many column="fam_kuid" class="Family"/>
   </set>
</class>


Thanks for any help you may offer


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 28, 2006 9:00 am 
Beginner
Beginner

Joined: Mon Jul 26, 2004 4:29 pm
Posts: 45
Location: TX, USA
Section 11.11 of the Reference Guide seems to speak directly to your situation. Especially when it says:

Quote:
A special cascade style, delete-orphan, applies only to one-to-many associations, and indicates that the delete()
operation should be applied to any child object that is removed from the association.


and this:

Quote:
It doesn't usually make sense to enable cascade on a <many-to-one> or <many-to-many> association. Cascade
is often useful for <one-to-one> and <one-to-many> associations.


What I read here is that an association that is marked as "delete-orphan" is expected to be a parent/child type relationship, not one with potentially more than one parent... but I'm pretty new here, so maybe someone more experienced could verify this?

Hope this helps,


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.