-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Cascade delete with Optimistic control
PostPosted: Thu Mar 13, 2008 2:24 pm 
Newbie

Joined: Thu Oct 18, 2007 1:10 pm
Posts: 9
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.