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 ?