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.  [ 2 posts ] 
Author Message
 Post subject: many-to-one referencing a class with composite-id
PostPosted: Fri Nov 02, 2007 2:04 pm 
Newbie

Joined: Tue Jan 16, 2007 4:44 am
Posts: 5
Hibernate version: 1.2 GA

Classes:
Let's say we have :

class Person {
PersonPk Id;
DateTime DateOfBirth
}

class PersonPk {
string FirstName,
string LastName,
}

Car {
int id
string Name,
double Price,
Person Owner, <<< how to map this ?
}

Tables
Person {
[PK] FirstName varchar(20),
[PK] LastName varchar(20),
DateOfBirth DateTime
}

Car {
[PK] Id int,
name varchar(20),
price double,
[FK] OwnerFirstName varchar(20),
[FK] OwnerLastName varchar(20)
}

Question
How do i write the Car's mapping to reference its owner. All documentations i've found seem to reference only class with single Id.

Note
1) I've tried things like
<class name=Car>
...
<many-to-one Name="Owner" class="Person" >
<column name="OwnerFirstName" />
<column name="OwnerLastName" />
</many-to-one>
</class>
but of course, nhibernate complains about this.

2) the classes and table schema are simplified to help you understant what i'm want to know.

_________________
=====
Nhibernate rox !

here is my (empty) blog


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 02, 2007 3:33 pm 
Newbie

Joined: Tue Jan 16, 2007 4:44 am
Posts: 5
Sorry, that was working ...

You can use
<many-to-one ...>
<column name="" />
<column name="" />
...
</many-to-one>

NHibernate will use the declaration order to match columns with the composite pk of the referenced class.

_________________
=====
Nhibernate rox !

here is my (empty) blog


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