-->
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: one-to-many mapping using alternate key
PostPosted: Wed Nov 01, 2006 1:09 pm 
Newbie

Joined: Mon Jul 18, 2005 7:45 am
Posts: 16
Hi - We have 2 tables:

account
---------------
ID (int, PK)
accountID (string, unique)
...

portfolio
---------------
ID (int, PK)
portfolioID (string, unique)
accountID (string, FK to account.accountID)
...


We want to map a standard bi-directional one-to-many relationship but the FK in the child table references an alternative key in the parent table.

The many-to-one side seems to work fine using the property-ref attribute to specify the column for the join - e.g.

<many-to-one name="Account" column="AccountID" property-ref="AccountId" not-null="true" />

However, we are unable to get the same thing working for the one-to-many side, using a bag. NHibernate seems to assume that the portfolio FK maps to the <id> column of the account table. Is there any work around for this?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 01, 2006 1:50 pm 
Beginner
Beginner

Joined: Fri Oct 20, 2006 8:02 am
Posts: 36
you should specify the foreing-key at the key element.

Example:
Code:
<bag name="Portfolios" cascade="all" lazy="true" inverse="true" >
   <key column="accountID" foreign-key="accountID" />
   <one-to-many class="portfolio" />
</bag>


something like that...


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.