I am using the version property for optimistic control and have one to many relation as follows:
Person is the Parent object and it has the following mapping.
<class name="PERSPerson" table="[dbo].[PERS_Person]" optimistic-lock="version" lazy="false">
//id
<version name="LastUpdateVersion" column="LastUpdateVersion" type="type, namespace" generated="always" unsaved-value="null" />
//other properties
<bag name="PERSPersonAddress" cascade="all-delete-orphan" inverse="true" lazy="false">
<key>
<column name= "`Person_id`" />
</key >
<one-to-many class="PERSPersonAddress" />
</bag >
<bag name="PERSPersonEMails" cascade="all-delete-orphan" inverse="true" lazy="false">
<key>
<column name= "Person_id" />
</key >
<one-to-many class="PERSPersonEMail" />
</bag >
<bag name="PERSPersonPhones" cascade="all-delete-orphan" inverse="true" lazy="false" >
<key>
<column name= "Person_id" />
</key >
<one-to-many class="PERSPersonPhone" />
</bag >
In the child objects, I have the similar optimistic control and the mapping document defines the relation as
<many-to-one name="PERSPerson" class="PERSPerson" cascade="save-update" outer-join="auto" lazy="false">
<column name="`Person_id`"/>
</many-to-one >
That said, I am trying to do a delete of the PERSON object so that all the associated objects should be deleted. I do this by getting the person object with person id and then deleting it as a two step process in separate sessions.
When I do this, I get the following error:
"Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) for PERSPerson instance with identifier: id"
As for the SQL statements, I see selects statements as part of Get. During Delete, there is a Update statement for PERSON table ( Why?) and then a select to get the last update version followed by the delete statements.
I think the failure happens because of the update during the delete. Anyone know why this would happen?
One thing I noted is, if I remove the optimistic-control in the mapping file for the parent object, delete works fine without errors.
Appreciate your help.
|