-->
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.  [ 4 posts ] 
Author Message
 Post subject: Hibernate and Composite Key
PostPosted: Sat Oct 28, 2006 2:06 pm 
Newbie

Joined: Sat Oct 28, 2006 1:57 pm
Posts: 6
Hi alll


We are facing a problem with composite key and one to many assiciations.

We have a 2 tables Person and Person_Contacts. Between person and person_contacts there is a one-to-many association.

Person_contact table has a composite key made of PersonId and ContactMethod.

We have done the following mapping in our Person.hbm.xml


<set name="personContact" table="PERSON_CONTACT" cascade = "all">
<key column ="PTC_PER_PARTY_ID"/>
<one-to-many class="PersonContact" />
</set>

But when delete a Person recod .. we get an error saying Person Id cant be set to null in Person_Contact

But what we want is when we delete a person record it should delete all the records in teh Person_Contacts table also.


Can any one please suggest a solution to this problem


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 28, 2006 11:51 pm 
Regular
Regular

Joined: Wed Jul 27, 2005 2:33 am
Posts: 118
Quote:
But what we want is when we delete a person record it should delete all the records in teh Person_Contacts table also.


Try this:

Code:
<set name="personContact" table="PERSON_CONTACT" cascade = "all-delete-orphan" inverse="true">
  <key column ="PTC_PER_PARTY_ID"/>
  <one-to-many class="PersonContact" />
</set>


Top
 Profile  
 
 Post subject: Re: Hibernate and Composite Key
PostPosted: Sun Oct 29, 2006 12:51 am 
Senior
Senior

Joined: Tue Aug 23, 2005 8:52 am
Posts: 181
RajAdi wrote:
<set name="personContact" table="PERSON_CONTACT" cascade = "all">
<key column ="PTC_PER_PARTY_ID"/>
<one-to-many class="PersonContact" />
</set>

But when delete a Person recod .. we get an error saying Person Id cant be set to null in Person_Contact


I just tried the same on mysql with innodb and it worked for me(Deleted the child when the Person record is deleted). Can you show the mapping on the other side ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 30, 2006 5:34 am 
Newbie

Joined: Sat Oct 28, 2006 1:57 pm
Posts: 6
THANKS GUYS BY SETTING IT AS "all-delete-orphan" inverse="true" IT WORKED .


Regards
Rajadi


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.