I went thru a mapping excercise recently and spent several hours trying to figure out why I kept getting emtpy sets when there should've been values.
When I was debugging I found that the values from the component were being bound in the wrong order to the statement.
It took me quite some time but I finally realized that they key to the set has to be mapped in the
same order as the columns are mapped in the
composite-id of the actual
one-to-many class.
my successful attempt is included
Code:
<class name="AcaVehicle" table="ACA_VEHICLE">
<composite-id class="VehicleID" name="vehicleId" unsaved-value="none">
<key-property column="C_VEHICLE_ID" name="CVehicleId" type="integer" />
<key-property column="C_VEH_AMEND_NUM2" name="CVehAmendNum2" type="integer" />
<key-property column="C_VEH_AMEND_NUM1" name="CVehAmendNum1" type="integer" />
<key-property column="C_POLICY_ID" name="CPolicyId" type="integer" />
<key-property column="C_POL_AMEND_NUM2" name="CPolAmendNum2" type="integer" />
<key-property column="C_POL_AMEND_NUM1" name="CPolAmendNum1" type="integer" />
</composite-id>
<set lazy="true" order-by="C_VEHICLE_ID" name="coverages" inverse="false" cascade="save-update">
<key >
<column name="C_VEHICLE_ID" not-null="true" />
<column name="C_VEH_AMEND_NUM1" not-null="true" />
<column name="C_VEH_AMEND_NUM2" not-null="true" />
<column name="C_POLICY_ID" not-null="true" />
<column name="C_POL_AMEND_NUM1" not-null="true" />
<column name="C_POL_AMEND_NUM2" not-null="true" />
</key>
<one-to-many class="AcaCoverage" />
</set>
..
/************************************/
<class name="AcaCoverage" table="ACA_COVERAGE">
<composite-id unsaved-value="none" class="AcaCoverageId" name="AcaCoverageId">
<key-property column="C_VEHICLE_ID" name="CVehicleId" type="integer" />
<key-property column="C_VEH_AMEND_NUM2" name="CVehAmendNum2" type="integer" />
<key-property column="C_VEH_AMEND_NUM1" name="CVehAmendNum1" type="integer" />
<key-property column="C_POLICY_ID" name="CPolicyId" type="integer" />
<key-property column="C_POL_AMEND_NUM2" name="CPolAmendNum2" type="integer" />
<key-property column="C_POL_AMEND_NUM1" name="CPolAmendNum1" type="integer" />
<key-property column="C_CVRG_AMEND_NUM2" name="CCvrgAmendNum2" type="integer" />
<key-property column="C_CVRG_AMEND_NUM1" name="CCvrgAmendNum1" type="integer" />
<key-property column="C_COVERAGE_ID" name="CCoverageId" type="integer" />
</composite-id>
...
keywords: bind, order, composite, foreign, property[/i]