Here's the mapping document:
<hibernate-mapping>
<class name="acme.membership.domain.JMember">
<id name="id" type="int" unsaved-value="0">
<generator class="increment"></generator>
</id>
<property name="lastName" />
<property name="firstName" />
<property name="birthDate" type="calendar" />
<joined-subclass name="acme.membership.domain.PrimaryMember"
table="primarymember">
<key column="id" />
<array name="dependents" table="dependent"
cascade="save-update">
<key column="id" />
<index column="i" />
<one-to-many class="acme.membership.domain.Dependent" />
</array>
<many-to-one name="address" cascade="save-update" />
<many-to-one name="contactInfo" cascade="save-update" />
</joined-subclass>
<joined-subclass name="acme.membership.domain.Dependent"
table="dependent">
<key column="id" />
<property name="type" />
</joined-subclass>
</class>
</hibernate-mapping>
Have a look at this trace (with SQL and binding info is enabled):
Some correct inserts into the dependent table occured previously, and now Hibernate is doing some subsequent updates and updating both the id field ('id') as well as the index field ('i').
....
Hibernate: update dependent set id=?, i=? where id=?
21:21:13,785 DEBUG IntegerType:46 - binding '1' to parameter: 1
21:21:13,785 DEBUG IntegerType:46 - binding '2' to parameter: 3
21:21:13,785 DEBUG IntegerType:46 - binding '0' to parameter: 2
Hibernate: update dependent set id=?, i=? where id=?
21:21:13,785 DEBUG IntegerType:46 - binding '1' to parameter: 1
21:21:13,785 DEBUG IntegerType:46 - binding '3' to parameter: 3
21:21:13,785 DEBUG IntegerType:46 - binding '1' to parameter: 2
21:21:13,795 WARN JDBCExceptionReporter:38 - SQL Error: -803, SQLState: 23505
21:21:13,795 ERROR JDBCExceptionReporter:46 - [IBM][CLI Driver][DB2/NT] SQL0803N One or more values in the INSERT statement, UPDATE statement, or foreign key update caused by a DELETE statement are not valid because the primary key, unique constraint or unique index identified by "1" constrains table "AMANJI.DEPENDENT" from having duplicate rows for those columns. SQLSTATE=23505
|