Code:
// This is the current code, which seems to work OK.
// mappings - the treatment detail records are actually called FactorValues
<hibernate-mapping>
<class name="org.laf.ccs.persistence.Treatment" table="r_treatment" catalog="ccsphs">
<id name="treatmentId" type="java.lang.Long">
<column name="TREATMENT_ID" />
<generator class="native" />
</id>
[ Treatment fields ... ]
<set name="factorValues" inverse="true">
<key>
<column name="TREATMENT_ID" not-null="true" />
</key>
<one-to-many class="org.laf.ccs.persistence.FactorValue" />
</set>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="org.laf.ccs.persistence.FactorValue" table="r_factor_value" catalog="ccsphs">
<id name="factorValueId" type="java.lang.Long">
<column name="FACTOR_VALUE_ID" />
<generator class="native" />
</id>
<many-to-one name="treatment" class="org.laf.ccs.persistence.Treatment" fetch="select">
<column name="TREATMENT_ID" not-null="true" />
</many-to-one>
[ FactorVaue fields ... ]
</class>
</hibernate-mapping>
// update code
// Delete old treatment values
for (FactorValue factorValue : treatment.getFactorValues()) {
session.update(factorValue); // re-attach
session.delete( factorValue );
}
// add new treatment values
Set<FactorValue> factorValues = // code to create new FactorValues;
treatment.setFactorValues(factorValues);
session.save( treatment );
for (FactorValue factorValue : factorValues) session.save( factorValue );
// Runtime SQL
Note that the old FactorValues being deleted have IDs 17-24.
The code first does an update (!!!!!) and then deletes these.
The new FactorValues have IDs 25-31 and are the only remaining ones in the DB after the operation, as expected.
For some reason the code first creates the new FactorValues.
[CCS_R1] INFO [http-8080-Processor23] Util.incidentToTreatment(39) | NewTreatmentController.onSubmit: treatmentId=1
[CCS_R1] DEBUG [http-8080-Processor23] SQL.log(393) | insert into ccsphs.r_factor_value (TREATMENT_ID, FACTORSTRINGID, FLOAT_VALUE, DATE_VALUE, FACTOR_ID) values (?, ?, ?, ?, ?)
[CCS_R1] DEBUG [http-8080-Processor23] LongType.nullSafeSet(80) | binding '1' to parameter: 1
[CCS_R1] DEBUG [http-8080-Processor23] IntegerType.nullSafeSet(80) | binding '2015' to parameter: 2
[CCS_R1] DEBUG [http-8080-Processor23] FloatType.nullSafeSet(80) | binding '22.0' to parameter: 3
[CCS_R1] DEBUG [http-8080-Processor23] IntegerType.nullSafeSet(80) | binding '5' to parameter: 5
[CCS_R1] DEBUG [http-8080-Processor23] SQL.log(393) | insert into ccsphs.r_factor_value (TREATMENT_ID, FACTORSTRINGID, FLOAT_VALUE, DATE_VALUE, FACTOR_ID) values (?, ?, ?, ?, ?)
[CCS_R1] DEBUG [http-8080-Processor23] LongType.nullSafeSet(80) | binding '1' to parameter: 1
[CCS_R1] DEBUG [http-8080-Processor23] IntegerType.nullSafeSet(80) | binding '5007' to parameter: 2
[CCS_R1] DEBUG [http-8080-Processor23] FloatType.nullSafeSet(73) | binding null to parameter: 3
[CCS_R1] DEBUG [http-8080-Processor23] IntegerType.nullSafeSet(80) | binding '4' to parameter: 5
[CCS_R1] DEBUG [http-8080-Processor23] SQL.log(393) | insert into ccsphs.r_factor_value (TREATMENT_ID, FACTORSTRINGID, FLOAT_VALUE, DATE_VALUE, FACTOR_ID) values (?, ?, ?, ?, ?)
[CCS_R1] DEBUG [http-8080-Processor23] LongType.nullSafeSet(80) | binding '1' to parameter: 1
[CCS_R1] DEBUG [http-8080-Processor23] IntegerType.nullSafeSet(80) | binding '50007' to parameter: 2
[CCS_R1] DEBUG [http-8080-Processor23] FloatType.nullSafeSet(73) | binding null to parameter: 3
[CCS_R1] DEBUG [http-8080-Processor23] IntegerType.nullSafeSet(80) | binding '3' to parameter: 5
[CCS_R1] DEBUG [http-8080-Processor23] SQL.log(393) | insert into ccsphs.r_factor_value (TREATMENT_ID, FACTORSTRINGID, FLOAT_VALUE, DATE_VALUE, FACTOR_ID) values (?, ?, ?, ?, ?)
[CCS_R1] DEBUG [http-8080-Processor23] LongType.nullSafeSet(80) | binding '1' to parameter: 1
[CCS_R1] DEBUG [http-8080-Processor23] IntegerType.nullSafeSet(80) | binding '1' to parameter: 2
[CCS_R1] DEBUG [http-8080-Processor23] FloatType.nullSafeSet(73) | binding null to parameter: 3
[CCS_R1] DEBUG [http-8080-Processor23] IntegerType.nullSafeSet(80) | binding '1' to parameter: 5
[CCS_R1] DEBUG [http-8080-Processor23] SQL.log(393) | insert into ccsphs.r_factor_value (TREATMENT_ID, FACTORSTRINGID, FLOAT_VALUE, DATE_VALUE, FACTOR_ID) values (?, ?, ?, ?, ?)
[CCS_R1] DEBUG [http-8080-Processor23] LongType.nullSafeSet(80) | binding '1' to parameter: 1
[CCS_R1] DEBUG [http-8080-Processor23] IntegerType.nullSafeSet(80) | binding '13' to parameter: 2
[CCS_R1] DEBUG [http-8080-Processor23] FloatType.nullSafeSet(73) | binding null to parameter: 3
[CCS_R1] DEBUG [http-8080-Processor23] IntegerType.nullSafeSet(80) | binding '10' to parameter: 5
[CCS_R1] DEBUG [http-8080-Processor23] SQL.log(393) | insert into ccsphs.r_factor_value (TREATMENT_ID, FACTORSTRINGID, FLOAT_VALUE, DATE_VALUE, FACTOR_ID) values (?, ?, ?, ?, ?)
[CCS_R1] DEBUG [http-8080-Processor23] LongType.nullSafeSet(80) | binding '1' to parameter: 1
[CCS_R1] DEBUG [http-8080-Processor23] IntegerType.nullSafeSet(80) | binding '4005' to parameter: 2
[CCS_R1] DEBUG [http-8080-Processor23] FloatType.nullSafeSet(73) | binding null to parameter: 3
[CCS_R1] DEBUG [http-8080-Processor23] IntegerType.nullSafeSet(80) | binding '6' to parameter: 5
[CCS_R1] DEBUG [http-8080-Processor23] SQL.log(393) | insert into ccsphs.r_factor_value (TREATMENT_ID, FACTORSTRINGID, FLOAT_VALUE, DATE_VALUE, FACTOR_ID) values (?, ?, ?, ?, ?)
[CCS_R1] DEBUG [http-8080-Processor23] LongType.nullSafeSet(80) | binding '1' to parameter: 1
[CCS_R1] DEBUG [http-8080-Processor23] IntegerType.nullSafeSet(80) | binding '12' to parameter: 2
[CCS_R1] DEBUG [http-8080-Processor23] FloatType.nullSafeSet(73) | binding null to parameter: 3
[CCS_R1] DEBUG [http-8080-Processor23] IntegerType.nullSafeSet(80) | binding '9' to parameter: 5
[CCS_R1] DEBUG [http-8080-Processor23] SQL.log(393) | update ccsphs.r_survivor set CLINIC_ID=?, FIRST_NAME=?, LAST_NAME=?, ADDRESS1=?, ADDRESS2=?, CITY=?, STATE=?, ZIP=?, RELEASE_SIGNED=?, DOCTOR=?, SURVIVOR_STATUS=?, ACTIVE=?, SURVIVOR_CODE=? where SURVIVOR_ID=?
[CCS_R1] DEBUG [http-8080-Processor23] LongType.nullSafeSet(80) | binding '2' to parameter: 1
[CCS_R1] DEBUG [http-8080-Processor23] ByteType.nullSafeSet(80) | binding '1' to parameter: 9
[CCS_R1] DEBUG [http-8080-Processor23] StringType.nullSafeSet(80) | binding 'V' to parameter: 11
[CCS_R1] DEBUG [http-8080-Processor23] ByteType.nullSafeSet(80) | binding '1' to parameter: 12
[CCS_R1] DEBUG [http-8080-Processor23] StringType.nullSafeSet(80) | binding 'FRANK' to parameter: 13
[CCS_R1] DEBUG [http-8080-Processor23] LongType.nullSafeSet(80) | binding '1' to parameter: 14
[CCS_R1] DEBUG [http-8080-Processor23] SQL.log(393) | update ccsphs.r_treatment set LAST_UPDATER=?, SURVIVOR_ID=?, CREATED=?, UPDATED=?, TREATMENT_STATUS=? where TREATMENT_ID=?
[CCS_R1] DEBUG [http-8080-Processor23] LongType.nullSafeSet(80) | binding '6' to parameter: 1
[CCS_R1] DEBUG [http-8080-Processor23] LongType.nullSafeSet(80) | binding '1' to parameter: 2
[CCS_R1] DEBUG [http-8080-Processor23] TimestampType.nullSafeSet(80) | binding '2008-02-22 11:51:51' to parameter: 3
[CCS_R1] DEBUG [http-8080-Processor23] TimestampType.nullSafeSet(80) | binding '2008-02-22 11:51:51' to parameter: 4
[CCS_R1] DEBUG [http-8080-Processor23] StringType.nullSafeSet(80) | binding 'V' to parameter: 5
[CCS_R1] DEBUG [http-8080-Processor23] LongType.nullSafeSet(80) | binding '1' to parameter: 6
[CCS_R1] DEBUG [http-8080-Processor23] SQL.log(393) | update ccsphs.r_factor_value set TREATMENT_ID=?, FACTORSTRINGID=?, FLOAT_VALUE=?, DATE_VALUE=?, FACTOR_ID=? where FACTOR_VALUE_ID=?
[CCS_R1] DEBUG [http-8080-Processor23] LongType.nullSafeSet(80) | binding '1' to parameter: 1
[CCS_R1] DEBUG [http-8080-Processor23] IntegerType.nullSafeSet(80) | binding '13' to parameter: 2
[CCS_R1] DEBUG [http-8080-Processor23] FloatType.nullSafeSet(73) | binding null to parameter: 3
[CCS_R1] DEBUG [http-8080-Processor23] IntegerType.nullSafeSet(80) | binding '10' to parameter: 5
[CCS_R1] DEBUG [http-8080-Processor23] LongType.nullSafeSet(80) | binding '18' to parameter: 6
[CCS_R1] DEBUG [http-8080-Processor23] SQL.log(393) | update ccsphs.r_factor_value set TREATMENT_ID=?, FACTORSTRINGID=?, FLOAT_VALUE=?, DATE_VALUE=?, FACTOR_ID=? where FACTOR_VALUE_ID=?
[CCS_R1] DEBUG [http-8080-Processor23] LongType.nullSafeSet(80) | binding '1' to parameter: 1
[CCS_R1] DEBUG [http-8080-Processor23] IntegerType.nullSafeSet(80) | binding '50007' to parameter: 2
[CCS_R1] DEBUG [http-8080-Processor23] FloatType.nullSafeSet(73) | binding null to parameter: 3
[CCS_R1] DEBUG [http-8080-Processor23] IntegerType.nullSafeSet(80) | binding '3' to parameter: 5
[CCS_R1] DEBUG [http-8080-Processor23] LongType.nullSafeSet(80) | binding '17' to parameter: 6
[CCS_R1] DEBUG [http-8080-Processor23] SQL.log(393) | update ccsphs.r_factor_value set TREATMENT_ID=?, FACTORSTRINGID=?, FLOAT_VALUE=?, DATE_VALUE=?, FACTOR_ID=? where FACTOR_VALUE_ID=?
[CCS_R1] DEBUG [http-8080-Processor23] LongType.nullSafeSet(80) | binding '1' to parameter: 1
[CCS_R1] DEBUG [http-8080-Processor23] IntegerType.nullSafeSet(80) | binding '4017' to parameter: 2
[CCS_R1] DEBUG [http-8080-Processor23] FloatType.nullSafeSet(73) | binding null to parameter: 3
[CCS_R1] DEBUG [http-8080-Processor23] IntegerType.nullSafeSet(80) | binding '6' to parameter: 5
[CCS_R1] DEBUG [http-8080-Processor23] LongType.nullSafeSet(80) | binding '22' to parameter: 6
[CCS_R1] DEBUG [http-8080-Processor23] SQL.log(393) | update ccsphs.r_factor_value set TREATMENT_ID=?, FACTORSTRINGID=?, FLOAT_VALUE=?, DATE_VALUE=?, FACTOR_ID=? where FACTOR_VALUE_ID=?
[CCS_R1] DEBUG [http-8080-Processor23] LongType.nullSafeSet(80) | binding '1' to parameter: 1
[CCS_R1] DEBUG [http-8080-Processor23] IntegerType.nullSafeSet(80) | binding '12' to parameter: 2
[CCS_R1] DEBUG [http-8080-Processor23] FloatType.nullSafeSet(73) | binding null to parameter: 3
[CCS_R1] DEBUG [http-8080-Processor23] IntegerType.nullSafeSet(80) | binding '9' to parameter: 5
[CCS_R1] DEBUG [http-8080-Processor23] LongType.nullSafeSet(80) | binding '20' to parameter: 6
[CCS_R1] DEBUG [http-8080-Processor23] SQL.log(393) | update ccsphs.r_factor_value set TREATMENT_ID=?, FACTORSTRINGID=?, FLOAT_VALUE=?, DATE_VALUE=?, FACTOR_ID=? where FACTOR_VALUE_ID=?
[CCS_R1] DEBUG [http-8080-Processor23] LongType.nullSafeSet(80) | binding '1' to parameter: 1
[CCS_R1] DEBUG [http-8080-Processor23] IntegerType.nullSafeSet(80) | binding '4005' to parameter: 2
[CCS_R1] DEBUG [http-8080-Processor23] FloatType.nullSafeSet(73) | binding null to parameter: 3
[CCS_R1] DEBUG [http-8080-Processor23] IntegerType.nullSafeSet(80) | binding '6' to parameter: 5
[CCS_R1] DEBUG [http-8080-Processor23] LongType.nullSafeSet(80) | binding '23' to parameter: 6
[CCS_R1] DEBUG [http-8080-Processor23] SQL.log(393) | update ccsphs.r_factor_value set TREATMENT_ID=?, FACTORSTRINGID=?, FLOAT_VALUE=?, DATE_VALUE=?, FACTOR_ID=? where FACTOR_VALUE_ID=?
[CCS_R1] DEBUG [http-8080-Processor23] LongType.nullSafeSet(80) | binding '1' to parameter: 1
[CCS_R1] DEBUG [http-8080-Processor23] IntegerType.nullSafeSet(80) | binding '1' to parameter: 2
[CCS_R1] DEBUG [http-8080-Processor23] FloatType.nullSafeSet(73) | binding null to parameter: 3
[CCS_R1] DEBUG [http-8080-Processor23] IntegerType.nullSafeSet(80) | binding '1' to parameter: 5
[CCS_R1] DEBUG [http-8080-Processor23] LongType.nullSafeSet(80) | binding '19' to parameter: 6
[CCS_R1] DEBUG [http-8080-Processor23] SQL.log(393) | update ccsphs.r_factor_value set TREATMENT_ID=?, FACTORSTRINGID=?, FLOAT_VALUE=?, DATE_VALUE=?, FACTOR_ID=? where FACTOR_VALUE_ID=?
[CCS_R1] DEBUG [http-8080-Processor23] LongType.nullSafeSet(80) | binding '1' to parameter: 1
[CCS_R1] DEBUG [http-8080-Processor23] IntegerType.nullSafeSet(80) | binding '2015' to parameter: 2
[CCS_R1] DEBUG [http-8080-Processor23] FloatType.nullSafeSet(80) | binding '22.0' to parameter: 3
[CCS_R1] DEBUG [http-8080-Processor23] IntegerType.nullSafeSet(80) | binding '5' to parameter: 5
[CCS_R1] DEBUG [http-8080-Processor23] LongType.nullSafeSet(80) | binding '21' to parameter: 6
[CCS_R1] DEBUG [http-8080-Processor23] SQL.log(393) | update ccsphs.r_factor_value set TREATMENT_ID=?, FACTORSTRINGID=?, FLOAT_VALUE=?, DATE_VALUE=?, FACTOR_ID=? where FACTOR_VALUE_ID=?
[CCS_R1] DEBUG [http-8080-Processor23] LongType.nullSafeSet(80) | binding '1' to parameter: 1
[CCS_R1] DEBUG [http-8080-Processor23] IntegerType.nullSafeSet(80) | binding '5005' to parameter: 2
[CCS_R1] DEBUG [http-8080-Processor23] FloatType.nullSafeSet(73) | binding null to parameter: 3
[CCS_R1] DEBUG [http-8080-Processor23] IntegerType.nullSafeSet(80) | binding '4' to parameter: 5
[CCS_R1] DEBUG [http-8080-Processor23] LongType.nullSafeSet(80) | binding '24' to parameter: 6
[CCS_R1] DEBUG [http-8080-Processor23] SQL.log(393) | delete from ccsphs.r_factor_value where FACTOR_VALUE_ID=?
[CCS_R1] DEBUG [http-8080-Processor23] LongType.nullSafeSet(80) | binding '18' to parameter: 1
[CCS_R1] DEBUG [http-8080-Processor23] SQL.log(393) | delete from ccsphs.r_factor_value where FACTOR_VALUE_ID=?
[CCS_R1] DEBUG [http-8080-Processor23] LongType.nullSafeSet(80) | binding '17' to parameter: 1
[CCS_R1] DEBUG [http-8080-Processor23] SQL.log(393) | delete from ccsphs.r_factor_value where FACTOR_VALUE_ID=?
[CCS_R1] DEBUG [http-8080-Processor23] LongType.nullSafeSet(80) | binding '22' to parameter: 1
[CCS_R1] DEBUG [http-8080-Processor23] SQL.log(393) | delete from ccsphs.r_factor_value where FACTOR_VALUE_ID=?
[CCS_R1] DEBUG [http-8080-Processor23] LongType.nullSafeSet(80) | binding '20' to parameter: 1
[CCS_R1] DEBUG [http-8080-Processor23] SQL.log(393) | delete from ccsphs.r_factor_value where FACTOR_VALUE_ID=?
[CCS_R1] DEBUG [http-8080-Processor23] LongType.nullSafeSet(80) | binding '23' to parameter: 1
[CCS_R1] DEBUG [http-8080-Processor23] SQL.log(393) | delete from ccsphs.r_factor_value where FACTOR_VALUE_ID=?
[CCS_R1] DEBUG [http-8080-Processor23] LongType.nullSafeSet(80) | binding '19' to parameter: 1
[CCS_R1] DEBUG [http-8080-Processor23] SQL.log(393) | delete from ccsphs.r_factor_value where FACTOR_VALUE_ID=?
[CCS_R1] DEBUG [http-8080-Processor23] LongType.nullSafeSet(80) | binding '21' to parameter: 1
[CCS_R1] DEBUG [http-8080-Processor23] SQL.log(393) | delete from ccsphs.r_factor_value where FACTOR_VALUE_ID=?
[CCS_R1] DEBUG [http-8080-Processor23] LongType.nullSafeSet(80) | binding '24' to parameter: 1