I have an indexed one-to-many mapping. I add four children and save(), and the indices are 0..3 in the database. When the next child is added, for some reason the first four indices get set to zero, and the last one set to 4 (so now I have 0, 0, 0, 0, 4 in the database). Obviously a problem.
My (simplified) mappings are as follows:
Code:
<hibernate-mapping>
<class name="Envelope" table="ENVELOPE">
<id.../>
<one-to-one name="remittanceData" property-ref="envelope" class="RemittanceData"/>
<list name="stateHistory" table="ENV_STATE_HIST" cascade="all-delete-orphan" inverse="true">
<key column="ENVELOPE_ID"/>
<index column="SEQ"/>
<one-to-many class="StateHistory"/>
</list>
</class>
<class name="StateHistory" table="ENV_STATE_HIST">
<id .../>
<property column="SEQ" name="sequence"/>
<many-to-one column="ENVELOPE_ID" name="envelope"/>
<many-to-one column="STATE_ID" name="state" class="StateBase"/>
</class>
</hibernate-mapping>
and here is the offending SQL statement (from the log):
Code:
14:12:11,812 DEBUG SQL:223 - update ENV_STATE_HIST set SEQ=?, ENVELOPE_ID=?, STATE_ID=?, CREATED=?, CREATED_BY=? where ID=?
Hibernate: update ENV_STATE_HIST set SEQ=?, ENVELOPE_ID=?, STATE_ID=?, CREATED=?, CREATED_BY=? where ID=?
14:12:11,812 DEBUG BatcherImpl:227 - preparing statement
14:12:11,843 DEBUG EntityPersister:389 - Dehydrating entity: [StateHistory#2745]
14:12:11,843 DEBUG IntegerType:46 - binding '0' to parameter: 1
14:12:11,859 DEBUG LongType:46 - binding '687' to parameter: 2
14:12:11,859 DEBUG Cascades:341 - id unsaved-value strategy NULL
14:12:11,875 DEBUG LongType:46 - binding '0' to parameter: 3
14:12:11,875 DEBUG TimestampType:46 - binding '13 February 2004 14:06:41' to parameter: 4
14:12:11,906 DEBUG StringType:46 - binding 'test user' to parameter: 5
14:12:11,906 DEBUG LongType:46 - binding '2745' to parameter: 6
...(three more that also bind 0 to parameter: 1)...
I just can't for the life of me figure out why these updates are happenning.
Any suggestions?