Hi
I've got a class A which contains a collection of objects B. I add a load of B objects to the collection, then save A.
Looking at the debug, it seems to be doing an INSERT for each instance of B, which is great.
But then, it goes and does an UPDATE for each one too. And the values it uses are wrong.
Could anyone tell me a) why the updates are being done in the first place and b) where it's getting the values for the column
CHECKLIST_ITEM_ID. These are supposed to be foreign keys to another table. In the INSERT, the correct values are being used, but on the update, a FK Violation takes place, and I get a stacktrace.
The incorrect values that it uses are incremented by 1 each time, so I'm guessing it's the position of the record in the list. But that's just a guess.
The B records are getting stored in the DB, so I'd be happy if I could simply disable the UPDATES.
Here's my mapping:
Code:
<class name="A" table="CHECKLIST">
...
<list name="checklistItemRecords" table="CHECKLIST_ITEM_RECORD" lazy="false" fetch="select" outer-join="false" cascade="all">
<key column="CHECKLIST_ID" />
<list-index column="[b][color=red]CHECKLIST_ITEM_ID[/color][/b]"/>
<one-to-many class="com.lsb.uk.mqs.value.ChecklistItemRecordValue"/>
</list>
</class>
<class name="B" table="CHECKLIST_ITEM_RECORD">
<composite-id unsaved-value="any">
<key-property name="checklistItemId" column="CHECKLIST_ITEM_ID"/>
<key-property name="checklistId" column="CHECKLIST_ID"/>
</composite-id>
<property name="noteId" column="NOTE_ID"/>
<property name="checked" column="CHECKED"/>
</class>
Here's the (correct) INSERT that's being executed
DEBUG hibernate.SQL - insert into CHECKLIST_ITEM_RECORD (NOTE_ID, CHECKED, CHECKLIST_ITEM_ID, CHECKLIST_ID) values (?, ?, ?, ?)
DEBUG type.IntegerType - binding '0' to parameter: 1
DEBUG type.BooleanType - binding 'false' to parameter: 2
DEBUG type.IntegerType - binding '139' to parameter: 3
DEBUG type.IntegerType - binding '37' to parameter: 4
Here's the (incorrect) UPDATE
DEBUG hibernate.SQL - update CHECKLIST_ITEM_RECORD set CHECKLIST_ID=?,
CHECKLIST_ITEM_ID=? where CHECKLIST_ITEM_ID=? and CHECKLIST_ID=?
DEBUG type.IntegerType - binding '37' to parameter: 1
DEBUG type.IntegerType -
binding '0' to parameter: 2
DEBUG type.IntegerType - binding '120' to parameter: 3
DEBUG type.IntegerType - binding '37' to parameter: 4
Thanks