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.