I have the following mapping
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="Domain.User, Domain, Culture=neutral, PublicKeyToken=0113ab8eb077993" table="tblUser">
<cache usage="read-write"/>
<id name="ID" type="Int32" unsaved-value="0">
<column name="UserNID" sql-type="int" not-null="true" unique="true" index="PK_UserNID"/>
<generator class="native" />
</id>
<timestamp column="LastModifiedDTM" name="LastModifiedDtm" unsaved-value="undefined"/>
<property name="UserStatusID" type="Int32">
<column name="UserStatusID" sql-type="int" not-null="true"/>
</property>
<property name="Permissions" type="Int32">
<column name="Permissions" sql-type="int" not-null="true"/>
</property>
<property name="LastName" type="String">
<column name="LastName" length="50" sql-type="varchar" not-null="true"/>
</property>
<property name="FirstName" type="String">
<column name="FirstName" length="50" sql-type="varchar" not-null="true"/>
</property>
<property name="MiddleInitial" type="String">
<column name="MiddleInitial" length="1" sql-type="char" not-null="true"/>
</property>
...........
...........
<many-to-one name="Office" class="Domain.Office, Domain, Culture=neutral, PublicKeyToken=0113ab8eb077993">
<column name="OfficeNID" sql-type="int" not-null="true"/>
</many-to-one>
<many-to-one name="Role" class="Domain.Role, Domain, Culture=neutral, PublicKeyToken=0113ab8eb077993">
<column name="RoleID" sql-type="int" not-null="true"/>
</many-to-one>
<one-to-one name="UserPlanRole" class="Domain.UserPlanRole, Domain, Culture=neutral, PublicKeyToken=0113ab8eb077993" />
<bag name="UserContactInfo" inverse="true" lazy="false">
<key column="UserNID"/>
<one-to-many class="Domain.UserContactInfo, Domain, Culture=neutral, PublicKeyToken=0113ab8eb077993"/>
</bag>
</class>
</hibernate-mapping>
When I do update I get following exception
Code:
2009-09-03 14:53:19,982 ERROR Could not synchronize database state with session
NHibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [Domain.User#6700]
at NHibernate.Persister.Entity.AbstractEntityPersister.Check(Int32 rows, Object id, Int32 tableNumber, IExpectation expectation, IDbCommand statement)
at NHibernate.Persister.Entity.AbstractEntityPersister.Update(Object id, Object[] fields, Object[] oldFields, Object rowId, Boolean[] includeProperty, Int32 j, Object oldVersion, Object obj, SqlCommandInfo sql, ISessionImplementor session)
at NHibernate.Persister.Entity.AbstractEntityPersister.UpdateOrInsert(Object id, Object[] fields, Object[] oldFields, Object rowId, Boolean[] includeProperty, Int32 j, Object oldVersion, Object obj, SqlCommandInfo sql, ISessionImplementor session)
at NHibernate.Persister.Entity.AbstractEntityPersister.Update(Object id, Object[] fields, Int32[] dirtyFields, Boolean hasDirtyCollection, Object[] oldFields, Object oldVersion, Object obj, Object rowId, ISessionImplementor session)
at NHibernate.Action.EntityUpdateAction.Execute()
at NHibernate.Engine.ActionQueue.Execute(IExecutable executable)
at NHibernate.Engine.ActionQueue.ExecuteActions(IList list)
at NHibernate.Engine.ActionQueue.ExecuteActions()
at NHibernate.Event.Default.AbstractFlushingEventListener.PerformExecutions(IEventSource session)
Ironically this update works in my Sql 2005 server but not in Sql 2008 or Sql 2000 server(at least for the few cases I tried in Sql 2k5; different data but same schema though).
Also I see that my row is getting updated in Sql 2008. After the db update its failing with above exception.
Please note that my timestamp LastModifiedDTM column is DateTime in Sql Server.
Any help on the error would be appreciated
Thanks