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: Map a collection to an entity with a composite key
PostPosted: Tue Oct 27, 2009 8:36 pm 
Newbie

Joined: Tue Oct 27, 2009 7:54 pm
Posts: 1
I have two tables, say Customer and Order, both tables have a PK that consists of two columns.
Customer has as composite key columns A and B
Order has as composite key columns A and C

Now I want to create a bag in Customer that should map all Orders where column A has the same
value for both tables.

Code:
<class name="NHibernate.Customer, NHibernate" table="Customer">
   
    <!-- Composite key (primary key consists of more than one field -->
    <composite-id>
      <key-property name="A" column="pkA"></key-property>
      <key-property name="B" column="pkB"></key-property>
    </composite-id>
 
    <!-- One-to-many mapping-->
    <bag name="OrderList" lazy="false">
      <key>
        <column name="A"/>
      </key>
      <one-to-many class="Order"></one-to-many>
    </bag>
</class>

This results in this error:
Foreign key (FK497BA9679EAD9D16:Order [A])) must have same number of columns as the referenced primary key (Customer [A, B])

If I understand the error correctly, I need to define the bag with the second primary key as well.
But how should I do this? As the second PK only exist in one of the two and not in both tables the error seems to me 'odd'.
Is there any other way to accomplish this ?


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.