I have the following two tables:
Jobs
JobNo
DivisionID
NCRs
ID
JobNo
SpoilageJobNo
DivisionID
JobNo and DivisionID make up the composite key in the Jobs table (I know, but, unfortunately, it must be a composite key, since it is actually a representation of data from 4 different databases), and I need to join this key to the NCRs table as for JobNo, and for SpoilageJobNo.
I tried the following mappings:
<class name="Job" table="v_Jobs">
<composite-id name="Key">
<key-property name="JobNo"></key-property>
<key-many-to-one name="Division" class="Division" column="DivisionID"/>
</composite-id>
<bag name="NCRs">
<key>
<column name="JobNo"></column>
<column name="DivisionID"></column>
</key>
<one-to-many class="NCR"/>
</bag>
<bag name="SpoilageNCRs">
<key>
<column name="SpoilageJobNo"></column>
<column name="DivisionID"></column>
</key>
<one-to-many class="NCR"/>
</bag>
</class>
<class name="NCR" table="NCRs">
<id name="ID">
<generator class="identity"></generator>
</id>
<many-to-one name="Division"
class="Division"
column="DivisionID">
</many-to-one>
<many-to-one name="Job"
class="Job"
column="JobNo">
</many-to-one>
<many-to-one name="SpoilageJob"
class="Job"
column="SpoilageJobNo">
</many-to-one>
</class>
But I just get the error message Foreign key (FK480F1031931B2CA4:NCRs [JobNo])) must have same number of columns as the referenced primary key (v_Jobs [JobNo, DivisionID])
source
share