I struggling to map a Set relationship between two classes where the child does not have a reference to the parent id.
In other words, I need to map a relationship using some arbitrary properties of the two tables - but HOW?
This is a legacy database where I can not make any changes to the database
Class Ot_ncr is 'parent', Pnr_notes is 'child'
Currently the (working) mapping files look like this - I have omitted a lot of the detail for the sake of clarity:
Code:
<class name="Ot_ncr" table="OT_NCR" >
<id name="ncr_id" type="integer" >
<column name="NCR_ID" not-null="true" />
<generator class="assigned"/>
</id>
<property name="wo_no" type="string">
<column name="WO_NO" length="10" not-null="false" />
</property>
<property name="op_no" type="short">
<column name="OP_NO" not-null="false" />
</property>
.....
other properties
.....
</class>
Code:
<class name="Pnr_notes" table="PNR_NOTES">
<composite-id>
<key-property name="supplier_code" type="string">
<column length="10" name="SUPPLIER_CODE" not-null="false"/>
</key-property>
<key-property name="wo_no" type="string">
<column length="10" name="WO_NO" not-null="false"/>
</key-property>
<key-property name="op_no" type="short">
<column name="OP_NO" not-null="false"/>
</key-property>
<key-property name="unique_identifier" type="double">
<column name="UNIQUE_IDENTIFIER" not-null="false" precision="15" scale="0"/>
</key-property>
</composite-id>
<property name="po_no" type="string">
<column length="10" name="PO_NO" not-null="false"/>
</property>
.....
other properties
.....
</class>
I now need to introduce a Set (or other collection) mapping into the Class Ot_ncr; my first (not working) trial was as follows:
Code:
<class name="Ot_ncr" table="OT_NCR" >
<id name="ncr_id" type="integer" >
<column name="NCR_ID" not-null="true" />
<generator class="assigned"/>
</id>
<property name="wo_no" type="string">
<column name="WO_NO" length="10" not-null="false" />
</property>
<property name="op_no" type="short">
<column name="OP_NO" not-null="false" />
</property>
.....
other properties
.....
<set inverse="false" lazy="false" name="wo_pnr_notes" table="PNR_NOTES">
<key>
<column name="wo_no" />
<column name="op_no" />
</key>
<one-to-many class="Pnr_notes"/>
</set>
</class>
The thing to note is that the properties I need to map an association on 'wo_no' and 'op_no' are not full keys in either table.
I've tried a number of other ways - but so far without success - can this be done?