-->
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: Association n-n (many-to-many) with association class
PostPosted: Tue May 13, 2008 5:08 am 
Newbie

Joined: Fri May 02, 2008 11:06 am
Posts: 3
Hello

I have three tables family_members, addresses et family_member_address, that I want to map with three classes FamilyMember, FamilyMemberAddress and Address.

When a family member is deleted, the related associations *and* addresses must be deleted too. I have no problem to automatically suppress associations from database with Hibernate, but I have failed to do the same thing for addresses.

For now, I have written this in FamilyMember.hbm.xml :

Code:
[...]
      <set name="addresses" inverse="true" cascade="all-delete-orphan" lazy="true">
         <key column="id_member"/>
         <one-to-many class="FamilyMemberAddress"/>
      </set>
[...]



and in FamilyMemberAddress.hbm.xml :


Code:
<hibernate-mapping package="data">
   <class
      name="FamilyMemberAddress"
      table="family_member_address"
   >

      <composite-id name="id" class="FamilyMemberAddressPK">
         <key-many-to-one
            name="address"
            class="data.Address"
            column="id_address"
         />
         <key-many-to-one
            name="familyMember"
            class="FamilyMember"
            column="id_member"
         />
      </composite-id>

      <many-to-one
            name="addressType"
            column="id_address_type"
            class="data.AddressType"
            not-null="true"
      >
      </many-to-one>
   </class>   
</hibernate-mapping>



It seems we can't write something like cascade="all-delete-orphan" for the elements of the composite key of an association.

What is the best solution to automatically delete theses data ?

Maybe with <many-to-many> tags, but the documentation isn't clear about that when you have an association class. In the examples, the association table is not mapped with a class (or I don't understand how).

Do you have a working example ?


Thank you for your help

Syll


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.