-->
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: Mapping <composite-id> across objects
PostPosted: Tue Mar 15, 2005 11:30 am 
Newbie

Joined: Tue Mar 15, 2005 11:13 am
Posts: 2
I'm a newbie to Hibernate, but can't seem to find an answer in the Help docs or Google. I have a situation where my class structure is as follows:

Code:
public class AddressType {
     private String id;  // PK
     private String description;
     .....
}

public class Address {
     private int personId;  // 1 part of composite Id
     private AddressType addrType = ...; //  2nd part of composite Id
     .....
}


For Address, the Primary Key is actually a compound key: "Address.personId" and "Address.addrType.id". I believe I have the first part of the mapping which maps personId, but I can't figure out how to do the 2nd part (the mapping of "Address.addrType.id").

Code:
<hibernate-mapping>
     <class name="com.Address" table="Address">
          <composite-id>
                 <key-many-to-one entity-name="com.Person"
                                             name="personId"   
                                             column="PersonId"
                                             foreign-key="true"/>
          </composite-id>
     </class>
</hibernate-mapping>


I recognize that I could just remove the AddressType object and use regular addressTypeId as a class int variable, but I was hoping someone could shed some light on how I could fix this problem. Any help anyone could lend would be appreciated.


Hibernate version: 3rc1

Mapping documents:

Name and version of the database you are using: HSQLDB for testing, MS SQL Server 2000 for production


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.