-->
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 mapping problem
PostPosted: Thu May 24, 2007 11:27 am 
Beginner
Beginner

Joined: Wed Nov 08, 2006 8:24 am
Posts: 26
Location: Gothenburg, Sweden
I'm having a mapping problem (I think).

I have two tables, one parent table with a composite primary key, and another column that is unique (it's a legacy table...). There is a one-to-many relationship between parent and child.

The child table (also with a composite key) has a foreign key to the parent table's unique column (i.e. not the primary key).

How do I map this relationship i NHibernate?

In the parent mapping, can I do a one-to-many relationship from the unique column, to a compisite primary key in the child? And how do I map back in the child?


Top
 Profile  
 
 Post subject: Re: Many-to-one mapping problem
PostPosted: Fri May 25, 2007 9:34 am 
Senior
Senior

Joined: Thu Feb 09, 2006 1:30 pm
Posts: 172
d95pari wrote:
The child table (also with a composite key) has a foreign key to the parent table's unique column (i.e. not the primary key).

How do I map this relationship i NHibernate?

In the parent mapping, can I do a one-to-many relationship from the unique column, to a compisite primary key in the child? And how do I map back in the child?


See the documentation: http://www.hibernate.org/hib_docs/nhibernate/1.2/reference/en/html_single/#mapping-declaration-manytoone
taking special note of the property-ref attribute of the many-to-one mapping. This is what is used when you are not referencing the primary key.

As for the collection side, I'm drawing a bit of a blank. Handling composite keys is easy, just put multiple column elements in the key element. I'm not sure how you tell the collection to reference a different property. Maybe the property-ref is enough if you mark the collection as inverse? Give it a shot and see I suppose.


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.