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: StaleObjectStateException when deleting object
PostPosted: Tue Mar 11, 2008 5:35 am 
Beginner
Beginner

Joined: Tue Nov 27, 2007 1:25 pm
Posts: 24
Hello to all,

I have a Parent object with Childs.

Parent mapping:
Code:
<class name="Parent" table="PARENT" dynamic-insert="true" dynamic-update="true">

      <id name="Identity" column="PARENTID" type="Int64" unsaved-value="0">
         <generator class="sequence">
            <param name="sequence">SEQ__PARENT</param>
         </generator>
      </id>
      <timestamp name="RecordVersion" column="RECORDTIMESTAMP" generated="always"/>
      <property name="Name" column="NAME" type="String" not-null="true"/>

      <set name="Childs" lazy="true" fetch="select" generic="true" cascade="all-delete-orphan" inverse="true">
         <key>
            <column name="PARENTID" not-null="true"/>
         </key>
         <one-to-many class="Child"/>
      </set>
   </class>


Child mapping:
Code:
<class name="Child" table="CHILD" dynamic-insert="true" dynamic-update="true">

      <id name="Identity" column="CHILDID" type="Int64" unsaved-value="0">
         <generator class="sequence">
            <param name="sequence">SEQ__CHILD</param>
         </generator>
      </id>
      <timestamp name="RecordVersion" column="RECORDTIMESTAMP" generated="always"/>
      <property name="Name" column="NAME" type="String" not-null="true"/>
      
      <many-to-one class="Parent" name="Parent" column="PARENTID" fetch="select"  not-null="true" cascade="all-delete-orphan"/>
   </class>


I load parent and the I call Delete method and get this exception:
ERROR NHibernate.Impl.SessionImpl [(null)] <(null)> - could not synchronize database state with session
NHibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) for Tests.Child instance with identifier: 1
at NHibernate.Persister.Entity.AbstractEntityPersister.Check(Int32 rows, Object id, Int32 tableNumber, IExpectation expectation, IDbCommand statement)
at NHibernate.Persister.Entity.AbstractEntityPersister.Delete(Object id, Object version, Int32 j, Object obj, SqlCommandInfo sql, ISessionImplementor session, Object[] loadedState)
at NHibernate.Persister.Entity.AbstractEntityPersister.Delete(Object id, Object version, Object obj, ISessionImplementor session)
at NHibernate.Impl.ScheduledDeletion.Execute()
at NHibernate.Impl.SessionImpl.Execute(IExecutable executable)
at NHibernate.Impl.SessionImpl.ExecuteAll(IList list)
at NHibernate.Impl.SessionImpl.Execute()


The problem is that before delete statement, nHibernate issues an update statement which updates record versions of Parent and Child in database.

Regards,
Mindaugas


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.