Ok, maybe it is interesting for you. I've found my major problem: I'm actually using bidirectional references, which I wasn't aware of. Adding inverse="true" to my bidirectional references solves this problem.
:) I'm now stumbling across another problem, but that will be a new thread... ;) Fred F. On 29 Apr., 11:47, "Fred F." <[email protected]> wrote: > I want to tell you about my newest conclusions and ask you again for > help. > > For better reading I will shorten the mentioned MainObject to 'MO' and > ChildObject to 'CO'. > > I have taken the nhibernate sourcecode and discovered following > Method: > > ActionQueue.ExecuteActions() > > From here all committed database actions are executed. I have > recognized that 'ExecuteActions(collectionRemovals)' updates all > elements of all attached collections (CO). The update inside sets the > foreign keys to null (as seen in the logfile). Afterwards > 'ExecuteActions(deletions)' is executed and tries to delete the > corresponding objects (CO and afterwards MO). > > When it tries to delete CO it comes along > 'AbstractEntityPersister.Delete(...)' and this calls (within the > Method 'Check') the 'session.Batcher.ExecuteNonQuery(statement)' to > ask the database if there is an matching object (CO) in the database > to delete. But as this statement still asks for a object with filled > foreign keys, it doesn't find anything, because the objects were > updated already through the 'ExecuteActions(collectionRemovals)'- > method. This throws a StaleStateException and causes my delete to > fail. > > Why is NHibernate still looking for an object with setted foreign > keys, although the keys were just deleted by nhibernate itself? > > Is this a bug? Maybe I have misunderstood something. Please help me, > because otherwise I wouldn't be abled to use optimistic locking or > code something around it to make it work. But that would be really > ugly. > > Thanks in advance! > Fred F. > > On 28 Apr., 14:50, "Fred F." <[email protected]> wrote: > > > > > 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.- Zitierten Text ausblenden - > > - Zitierten Text anzeigen - --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
