We are getting a couple different strange errors out of nhibernate in our asp.net MVC 3 application. But only in the productions(field) environment, and only on our highest load application, and it only started after we upgraded from server 2003 to server 2012, and pointed to a new copy of our sybase DB at our new main data center, and released new code. (Of course we did all 3 on the same weekend, and so have no idea which caused it.)
The problems are happening all over, including in code we haven't touched in forever. We haven' changed the underlying nhibernate wrapper code. We also use fluent if that helps any.
Because of a design decision above my level we are only updating inserting and deleting with nhibernate, selects we do by hand... but all our erros are essentially "we(nh) wrote to the Db and things were out of synch)".
we basically fetch data manually, populate an EO, make our changes to the EO and tell nhibernate to handle updating it for us.
Here is one example error.
23 Nov 2015 07:02:10,925  [Error] OnActionExecuting : ProgrammerInfo Unexpected row count: -1; expected: 1; Details=NHibernate.StaleStateException: Unexpected row count: -1; expected: 1 at NHibernate.AdoNet.Expectations.BasicExpectation.VerifyOutcomeNonBatched(Int32 rowCount, IDbCommand statement) at NHibernate.AdoNet.NonBatchingBatcher.AddToBatch(IExpectation expectation) 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) at NHibernate.Event.Default.DefaultFlushEventListener.OnFlush(FlushEvent event) at NHibernate.Impl.SessionImpl.Flush() at NHibernate.Transaction.AdoTransaction.Commit() at JCDCHelper.NhAccess.BusinessObjects.NHSession.Commit() at CIS3G.BLL.BusinessObjects.CTTCredentialsBLL.SaveCredentials(CTTCredentialsVM record) at CIS3G.Controllers.TrainingStudentBasedController.SaveCredentials(CTTCredentialsVM criteria)
We also get stale state errors. we are using Structure map and are running out session wrapper in hybrid mode, to implement the session per request pattern. My firs thought was multithreadede access to session corrupting the state.. but the session per request pattern is suppoed to prevent this yes?
x.ForRequestedType() .AddInstances(z => z .OfConcreteType() .WithName("JCDC_HasTrans") .SetProperty(y => y.DBNameAndHasTran = "JCDC_HasTrans") ) .AddInstances(z => z .OfConcreteType() .WithName("JCDC_HasNoTrans") .SetProperty(y => y.DBNameAndHasTran = "JCDC_HasNoTrans") ) .AddInstances(z => z .OfConcreteType() .WithName("SPAMIS_HasTrans") .SetProperty(y => y.DBNameAndHasTran = "SPAMIS_HasTrans") ) .AddInstances(z => z .OfConcreteType() .WithName("SPAMIS_HasNoTrans") .SetProperty(y => y.DBNameAndHasTran = "SPAMIS_HasNoTrans") ) .CacheBy(InstanceScope.Hybrid);
The fact that it's load dependence leaned me towards a racing condition on multiple thread corrupting the state. Bu the more I've read the move I'm beginning to feel this is a "you are not using nhibernate right" problem
What else can be causing this
I know the -1,-1 error can be caused by double deleting an object, but that's thread related right?
The Nhibernate articles say to look at the generated sql and it'll explain the error, but i pull it out and de-parameterize it and the sql works fine.
This issue is hitting our customers pretty hard, Any guidance or help is appreciated, especially posts/links that will help be understand what can cause the nhibernate to throw the -1,1 and stale state exceptions, when threading is supposedly "handled".