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: Composite keys as foreign keys where db re-uses a column
PostPosted: Thu Sep 04, 2008 7:06 pm 
Newbie

Joined: Mon Mar 03, 2008 1:44 pm
Posts: 12
Location: Vancouver, BC
I am working with a legacy database (that I did not design, and unfortunately cannot change) that uses composite-keys for its code tables.

In tables that reference the code table, they typically have paired a "LanguageCode" value (eg. "EN") with some other kind of code value. I have built a composite key class for each code table, and NHibernate is handling the relationship without problem.

Unfortunately, it some cases they have created MULTIPLE composite foreign keys to different code tables, but all of them share the concept of the LanguageCode column as part of the composite key.

Below are my settings for the hbm.xml file where I have two of these composite keys. NHibernate is rejecting this when I attempt to save the row, because it is constructing an INSERT statement that includes the LanguageCode twice (once for each many-to-one tag).

Code:
   
<many-to-one name="PaymentMethod" class="PaymentMethod" fetch="select">
      <column name="PaymentMethodCode" length="10" not-null="true" />
      <column name="LanguageCode" length="3" not-null="true" />
    </many-to-one>

    <many-to-one name="PayOnAmount" class="PayOnAmount" fetch="select">
      <column name="PayOnAmountCode" length="10" not-null="true" />
      <column name="LanguageCode" length="3" not-null="true" />
    </many-to-one>


For now, I am not using the composite foreign key for classes where there are multiple composite foreign keys expected.

Is there any way to instruct NHibernate to not include LanguageCode mutiple times in its INSERT statement?

Thanks,

David


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.