Hello folks,
I've got a question concerning nhibernates behaviour with optimistic-
lock="all" and deleting objects.
I'm using NHibernate 2.0.1 and use composite-ids with two keys ('id'
and 'class').
I want to delete one object (MainObject) which contains a bag-
collection (with objects of type ChildObject) with the attribute
cascade="delete". When I try to delete this object MainObject, I get a
StaleStateException and nhibernate tells me: "Row was updated or
deleted by another transaction (or unsaved-value mapping was
incorrect): [ChildObject]".
I switched logging to 'verbose' and realized that nhibernate first
updates every element (ChildObject) of the collection. It sets my two
foreign keys to null first and tries to delete the elements
afterwards. But nhibernate realizes now that these objects were
changed and must not be deleted.
As nhibernate updates the objects by itself, I do not understand how
to delete objects with optimistic-lock="all". When I remove the bag-
collection from the MainObject-Mapping, the MainObject is deleted
without any problem. But my aim is to delete cascading from MainObject
to ChildObjects.
Mapping snippets of MainObject
[...]
<class name="MainObject" table="Main" lazy="true" optimistic-
lock="all" dynamic-update="true" where="discriminator='ABC'">
<composite-id>
<key-property name="customid" column="ID" />
<key-property name="classValue" column="CLASS" />
</composite-id>
[...]
<bag name="myChildren" cascade="delete">
<key>
<column name="FK_ID" />
<column name="FK_CLASS" />
</key>
<one-to-many class="ChildObject" />
</bag>
[...]
Mapping snippet of ChildObject
[...]
<class name="ChildObject" table="Child" lazy="true" optimistic-
lock="all" dynamic-update="true">
<composite-id>
<key-property name="customid" column="ID" />
<key-property name="classValue" column="CLASS" />
</composite-id>
[...]
Any hints for me?
Thanks in advance.
Fred F.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---