Given the
documentation on one-to-one mappings, I suspect this mapping to express the subsequent relationship:
Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" default-access="field">
<class name="SpringAir.Parts.PartOut, SpringAir.Objects" table="PartOut">
<id name="partOutId" type="Int32" column="PartOutId" unsaved-value="-1">
<generator class="hilo"><!--... blah, blah ... --></generator>
</id>
<many-to-one name="partIn" column="PartInId" cascade="all" unique="true" />
</class>
<class name="SpringAir.Parts.PartIn, SpringAir.Objects" table="PartIn">
<id name="partInId" type="Int32" column="PartInId" unsaved-value="-1">
<generator class="hilo"><!--... blah, blah ... --></generator>
</id>
<one-to-one name="partOut" property-ref="partIn" cascade="none" />
</class>
</hibernate-mapping>
Code:
Table PartIn:
-------------------
| PartInId (int) |
-------------------
Table PartOut:
--------------------------------------
| PartOutId (int) | PartInId (int) |
--------------------------------------
Code:
public class PartOut {
int partOutId;
PartIn partIn;
}
public class PartIn {
int partInId;
PartOut partOut;
}
According to the docs, this should correspond to a bidirectional one-to-one relationship with a unique foreign key.
However, the property-ref on the partIn side is loading the PartOut where PartOut.PartOutId=PartIn.PartInId, not PartOut.PartInId=PartIn.PartInId like I expected. Can anyone see anything wrong with the above?