Hello there,

We are having intermittent problems with a windows service running
over WCF (single instance) with NHibernate.

We are getting occasional errors that are causing our service to fail:

11:35:27.023 [26] ERROR
NHibernate.Event.Default.AbstractFlushingEventListener - Could not
synchronize database state with session
NHibernate.StaleStateException: Unexpected row count: 0; expected: 1
at
NHibernate.AdoNet.Expectations.BasicExpectation.VerifyOutcomeNonBatched(Int32
rowCount, IDbCommand statement)
at NHibernate.AdoNet.NonBatchingBatcher.AddToBatch(IExpectation
expectation)
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.Action.EntityDeleteAction.Execute()
at NHibernate.Engine.ActionQueue.Execute(IExecutable executable)
at NHibernate.Engine.ActionQueue.ExecuteActions(IList list)
at
NHibernate.Event.Default.AbstractFlushingEventListener.PerformExecutions(IEventSource
session)
12:44:13.357 [38] ERROR NHibernate.Transaction.AdoTransaction - Commit
failed
System.Data.SqlClient.SqlException: The COMMIT TRANSACTION request has
no corresponding BEGIN TRANSACTION.
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException
exception, Boolean breakConnection)
at
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject
stateObj)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior,
SqlCommand cmdHandler, SqlDataReader dataStream,
BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject
stateObj)
at
System.Data.SqlClient.TdsParser.TdsExecuteTransactionManagerRequest(Byte[]
buffer, TransactionManagerRequestType request, String transactionName,
TransactionManagerIsolationLevel isoLevel, Int32 timeout,
SqlInternalTransaction transaction, TdsParserStateObject stateObj,
Boolean isDelegateControlRequest)
at
System.Data.SqlClient.SqlInternalConnectionTds.ExecuteTransactionYukon(TransactionRequest
transactionRequest, String transactionName, IsolationLevel iso,
SqlInternalTransaction internalTransaction, Boolean
isDelegateControlRequest)
at System.Data.SqlClient.SqlInternalTransaction.Commit()
at System.Data.SqlClient.SqlTransaction.Commit()
at NHibernate.Transaction.AdoTransaction.Commit()

and

NHibernate.HibernateException: disconnected session
at
NHibernate.Collection.AbstractPersistentCollection.ForceInitialization()
at
NHibernate.Engine.StatefulPersistenceContext.InitializeNonLazyCollections()
at
NHibernate.Event.Default.DefaultLoadEventListener.AssembleCacheEntry(CacheEntry
entry, Object id, IEntityPersister persister, LoadEvent event)
at
NHibernate.Event.Default.DefaultLoadEventListener.LoadFromSecondLevelCache(LoadEvent
event, IEntityPersister persister, LoadType options)
at NHibernate.Event.Default.DefaultLoadEventListener.DoLoad(LoadEvent
event, IEntityPersister persister, EntityKey keyToLoad, LoadType
options)
at NHibernate.Event.Default.DefaultLoadEventListener.Load(LoadEvent
event, IEntityPersister persister, EntityKey keyToLoad, LoadType
options)
at NHibernate.Event.Default.DefaultLoadEventListener.OnLoad(LoadEvent
event, LoadType loadType)
at NHibernate.Impl.SessionImpl.FireLoad(LoadEvent event, LoadType
loadType)
at NHibernate.Impl.SessionImpl.InternalLoad(String entityName, Object
id, Boolean eager, Boolean isNullable)
at NHibernate.Type.EntityType.ResolveIdentifier(Object id,
ISessionImplementor session)
at NHibernate.Type.TypeFactory.Assemble(Object[] row,
ICacheAssembler[] types, ISessionImplementor session, Object owner)
at NHibernate.Cache.Entry.CacheEntry.Assemble(Object[] values, Object
result, Object id, IEntityPersister persister, IInterceptor
interceptor, ISessionImplementor session)
at
NHibernate.Event.Default.DefaultLoadEventListener.AssembleCacheEntry(CacheEntry
entry, Object id, IEntityPersister persister, LoadEvent event)
at
NHibernate.Event.Default.DefaultLoadEventListener.LoadFromSecondLevelCache(LoadEvent
event, IEntityPersister persister, LoadType options)
at NHibernate.Event.Default.DefaultLoadEventListener.DoLoad(LoadEvent
event, IEntityPersister persister, EntityKey keyToLoad, LoadType
options)
at NHibernate.Event.Default.DefaultLoadEventListener.Load(LoadEvent
event, IEntityPersister persister, EntityKey keyToLoad, LoadType
options)
at NHibernate.Event.Default.DefaultLoadEventListener.OnLoad(LoadEvent
event, LoadType loadType)
at NHibernate.Impl.SessionImpl.FireLoad(LoadEvent event, LoadType
loadType)
at NHibernate.Impl.SessionImpl.Get(Type clazz, Object id, LockMode
lockMode)
at X.X.DomainData.Implementation.CoreDao.GetEntity[T](Object id)
at X.X.DomainData.Implementation.UserDao.GetThing(Int32 engineerId)
at
X.X.CaseManagement.Implementation.Managers.UserManager.GetThing(Int32
engineerID)

Here is our session manager:

Code:
using System;
using NHibernate;
using NHibernate.Cfg;

namespace X.X.DomainData.Implementation
{
    public sealed class SessionManager
    {
        [ThreadStatic] private static ISession _session;
        private readonly Configuration _configuration;
        private readonly ISessionFactory _sessionFactory;

        #region Constructor

        #region Singleton

        public static SessionManager Instance
        {
            get { return Singleton.Instance; }
        }

        private class Singleton
        {
            internal static readonly SessionManager Instance = new
SessionManager();
        }

        #endregion

        private SessionManager()
        {
            _configuration = new Configuration();
            Configuration.Configure();

            Configuration.AddAssembly(GetType().Assembly);
            Configuration.Properties.Add("prevalenceBase", "cmm-
cache");

            //get the session factory
            _sessionFactory = Configuration.BuildSessionFactory();
        }

        #endregion

        #region NHibernate Setup

        public Configuration Configuration
        {
            get { return _configuration; }
        }


        internal ISessionFactory SessionFactory
        {
            get { return _sessionFactory; }
        }
        public void Close()
        {
            SessionFactory.Close();
        }

        #endregion

        #region NHibernate Sessions

        public ISession Session
        {
            get
            {
                ISession session = _session;

                //if it's an open session, that's all
                if (session != null && session.IsOpen)
                    return session;

                //if not open, open a new session
                return OpenSession();
            }
        }

        public ISession OpenSession()
        {
            ISession session = SessionFactory.OpenSession();
            _session = session;
            return session;
        }

        #endregion
    }
}


We are using this property:

<property name="current_session_context_class">thread_static</
property>

Can anybody explain what causes this error, why it causes the service
to freeze and how we can get around it?

Many thanks in anticipation,

Carl

-- 
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.

Reply via email to