NHibernate无法使数据库状态与会话同步

时间:2012-11-08 09:43:24

标签: c# nhibernate concurrency optimistic-locking

我正在检查NHibernate的日志文件,并发现随机错误,如下所示:

NHibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [MaltaIndependent.Modules._AutoGen.MemberImpl#353796206]
   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) in c:\Repository\Work\CodeBase\C#\+OpenSource\nHibernate\nhibernate-core-master-v3.3.1\src\NHibernate\Persister\Entity\AbstractEntityPersister.cs:line 2821
   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) in c:\Repository\Work\CodeBase\C#\+OpenSource\nHibernate\nhibernate-core-master-v3.3.1\src\NHibernate\Persister\Entity\AbstractEntityPersister.cs:line 2702
   at NHibernate.Persister.Entity.AbstractEntityPersister.Update(Object id, Object[] fields, Int32[] dirtyFields, Boolean hasDirtyCollection, Object[] oldFields, Object oldVersion, Object obj, Object rowId, ISessionImplementor session) in c:\Repository\Work\CodeBase\C#\+OpenSource\nHibernate\nhibernate-core-master-v3.3.1\src\NHibernate\Persister\Entity\AbstractEntityPersister.cs:line 3007
   at NHibernate.Action.EntityUpdateAction.Execute() in c:\Repository\Work\CodeBase\C#\+OpenSource\nHibernate\nhibernate-core-master-v3.3.1\src\NHibernate\Action\EntityUpdateAction.cs:line 79
   at NHibernate.Engine.ActionQueue.Execute(IExecutable executable) in c:\Repository\Work\CodeBase\C#\+OpenSource\nHibernate\nhibernate-core-master-v3.3.1\src\NHibernate\Engine\ActionQueue.cs:line 136
   at NHibernate.Engine.ActionQueue.ExecuteActions(IList list) in c:\Repository\Work\CodeBase\C#\+OpenSource\nHibernate\nhibernate-core-master-v3.3.1\src\NHibernate\Engine\ActionQueue.cs:line 125
   at NHibernate.Engine.ActionQueue.ExecuteActions() in c:\Repository\Work\CodeBase\C#\+OpenSource\nHibernate\nhibernate-core-master-v3.3.1\src\NHibernate\Engine\ActionQueue.cs:line 171
   at NHibernate.Event.Default.AbstractFlushingEventListener.PerformExecutions(IEventSource session) in c:\Repository\Work\CodeBase\C#\+OpenSource\nHibernate\nhibernate-core-master-v3.3.1\src\NHibernate\Event\Default\AbstractFlushingEventListener.cs:line 241

关于这个问题,我知道这是由于乐观并发而发生的,并且“预计”会发生。我的主要问题是堆栈跟踪 - 它没有说明它发生的位置,它开始了行NHibernate.Event.Default.AbstractFlushingEventListener.PerformExecution。我尝试下载NHibernate源代码并看一看,但是为什么没有显示完整的堆栈跟踪也没有多大意义。我有其他类似错误的堆栈跟踪,这些错误将我带到Transaction.Commit()行。任何想法如何找到哪一段代码实际上是在抛出错误?

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,事实证明我在映射字段上设置了LazyLoad(不是引用或hasmany)。

NH应该告诉你哪个对象导致了错误

希望你能尽快解决这个问题