-->
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: Many-to-one between two composite id
PostPosted: Tue Mar 02, 2004 8:46 pm 
Beginner
Beginner

Joined: Tue Feb 03, 2004 10:12 pm
Posts: 20
Location: San Francisco
I have two classes Person and Member.
Person primary key is a composite id {personA_id,cityA_id}
Member primary key is a composity id {personB_id, cityB_id, membership_id}

I have:
Code:
public class Member {
private MemberPK memberKey;
....
}

public class MemberPK implements Serializable {
private long personBid;
private long cityBid;
private long membershipid;

....
}

and
Code:
public class Person {
private PersonPK personKey;
...
}

public class PersonPK implements Serializable {
private long personAid;
private long cityAid;

....
}



I'd like to add a many-to-one relationship to Member.

Code:
public class Member {
private MemberPK memberKey;
private Person person;
....
}


I can't find any way to indicate in the mapping that Member has a many-to-one relationship with Person.

I have:
Code:
<class name="Person" table="persons" mutable="false">
   <composite-id name="personKey" class="PersonPK">
      <key-property name="personAid" type="long" column="personA_id"/>
      <key-property name="cityAid" type="long" column="cityA_id"/>
   </composite-id>
   ....
</class>


I tried:
Code:
<class name="Member" table="members" mutable="false">
   <composite-id name="memberKey" class="MemberPK">
      <key-property name="membershipid" type="long" column="membership_id"/>
      <key-property name="personBid" type="long" column="personB_id"/>
      <key-property name="cityBid" type="long" column="cityB_id"/>
   </composite-id>
   ....
   <many-to-one class="Person" name="person" outer-join="true" insert="false" update="false">
      <column name="personB_id"/>
      <column name="cityB_id"/>
   </many-to-one>   
</class>


and even tried:
Code:
<class name="Member" table="members" mutable="false">
   <composite-id name="memberKey" class="MemberPK">
      <key-property name="membershipid" type="long" column="membership_id"/>
      <key-many-to-one name="person" class="Person">
         <column name="personB_id"/>
         <column name="cityB_id"/>
      </key-many-to-one>
   </composite-id>
</class>


And it didn't work. I think key-many-to-one works well to link a table with a composite id to a regular table, but I haven't found how to declare a relationship between two tables with composite id.
Thanks.

_________________
Nicolas


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 03, 2004 2:14 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
What do you mean by and it didn't work

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 03, 2004 3:47 pm 
Beginner
Beginner

Joined: Tue Feb 03, 2004 10:12 pm
Posts: 20
Location: San Francisco
Sorry for the lack of stacktrace. Now I got this mapping to work. I have played with it so much I can't figure out now it is working how it could have failed though I suspect I got the key order wrong under the many-to-one tag. Please ignore my post.

Thanks

_________________
Nicolas


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 03, 2004 4:22 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
That was probably the key order. It's a common mistake.

_________________
Emmanuel


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.