Hi
I'm having trouble with mapping composite key relationships in a legacy database. If someone could give me a steer in the right direction for the relationship below, I'd really appreciate it.
This is a parent-child relationship, where the parent table defines an employee's Position History, and the child PositionDetails table holds more information about the positions.
Code:
Table: PositionHistory
Columns:
coy smallint [pk]
emp_number int [pk]
posn_history_date datetime [pk]
posit_work_area char(4)
posit_para smallint
posit_line smallint
posit_seq smallint
posit_tsh_seq smallint
audit_verify_time datetime
Table: PositionDetails
Columns:
coy smallint [pk]
posit_work_area char(4) [pk]
posit_para smallint [pk]
posit_line smallint [pk]
posit_seq smallint [pk]
posit_tsh_seq smallint [pk]
posit_eff_date datetime [pk]
designation varchar(40)
audit_verify_time datetime
I want to populate a "PositionDetails" collection in my PositionHistory class.
I've tried countless variations in my mapping file, but whatever I try I come back to the same error: "Foreign key in table PositionDetails must have same number of columns as referenced primary key in table PositionHistory".
It looks like NHibernate is trying to map the Primary Key of PositionDetails to the Primary Key of PositionHistory, instead of using the posit_* columns.
The most recent version of my mapping file is:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Core" namespace="Core.Domain">
<class name="PositionHistory" table="PositionHistory" lazy="true">
<composite-id name="Pk" class="PositionHistoryPk">
<key-property name="Company" column="coy" />
<key-property name="EmpNumber" column="emp_number" />
<key-property name="EffectiveDate" column="posn_history_date" />
</composite-id>
<version name="Timestamp" column="audit_verify_time" type="Timestamp" />
<map name="Position" lazy="true" order-by="posit_eff_date">
<key>
<column name="coy" />
<column name="posit_work_area" />
<column name="posit_para" />
<column name="posit_line" />
<column name="posit_seq" />
<column name="posit_tsh_seq" />
</key>
<index type="timestamp">
<column name="posit_eff_date" />
</index>
<one-to-many class="PositionDetails" />
</map>
</class>
<class name="PositionDetails" table="PositionDetails" lazy="true">
<composite-id name="Pk" class="PositionPk">
<key-property name="Company" column="coy" />
<key-property name="WorkArea" column="posit_work_area" />
<key-property name="Paragraph" column="posit_para" />
<key-property name="Line" column="posit_line" />
<key-property name="Sequence" column="posit_seq" />
<key-property name="TshSeq" column="posit_tsh_seq" />
<key-property name="EffectiveDate" column="posit_eff_date" />
</composite-id>
<version name="Timestamp" column="audit_verify_time" type="Timestamp" />
<property name="Designation" column="designation" />
</class>
</hibernate-mapping>
Please tell me what changes I need to make to this mapping file to populate the "PositionDetails" collection in my PositionHistory class?
Thanks,
Andrew