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.  [ 3 posts ] 
Author Message
 Post subject: InvalidOperationException at SessionImpl.FlushEverything()
PostPosted: Mon Jan 05, 2009 6:43 pm 
Newbie

Joined: Mon Jan 05, 2009 6:17 pm
Posts: 1
Hello,

A 'Collection was modified; enumeration operation may not execute.' exception has occurred a few times when trying to get the unique result of a query. I haven't been able to replicate this yet..

This seems to be happening deep w/in NHibernate, after it tries to automatically flush the session. For some reason, it fails when printing out the list of entities to the log.

I won't be able to disable log debug mode, so for this specific instance I'm currently considering just switching FlushMode to manual... But I seriously still don't understand how the collection is being modified...

I've been told this same problem happens from time to time elsewhere in the system, e.g. from a CriteriaImp.List<T>.

Any help / suggestions would be appreciated!

Thanks~


Hibernate version:
1.2.1.4000

Name and version of the database you are using:
SQL Server 2005

Code:
Code:
using (NHibernate.ISession session1 = NHibernateSessionManager.Instance.GetSession<DomainRef.FormInstance>(appSession))
                {
                    IQuery q = session1.CreateQuery("FROM FormInstance instance WHERE instance.ReferenceNumber = :ReferenceNumber").SetInt32("ReferenceNumber", referenceNumber);
                    formInstance = q.UniqueResult<DomainRef.FormInstance>();
                }


NHibernate Code:
Code:
private void FlushEverything()
{
    log.Debug("flushing session");
    this.interceptor.PreFlush(this.entitiesByKey.Values);
    this.PreFlushEntities();
    this.PreFlushCollections();
    this.flushing = true;
    try
    {
        this.FlushEntities();
        this.FlushCollections();
    }
    finally
    {
        this.flushing = false;
    }
    if (log.IsDebugEnabled)
    {
        log.Debug(string.Concat(new object[] { "Flushed: ", this.insertions.Count, " insertions, ", this.updates.Count, " updates, ", this.deletions.Count, " deletions to ", this.entityEntries.Count, " objects" }));
        log.Debug(string.Concat(new object[] { "Flushed: ", this.collectionCreations.Count, " (re)creations, ", this.collectionUpdates.Count, " updates, ", this.collectionRemovals.Count, " removals to ", this.collectionEntries.Count, " collections" }));
        new Printer(this.factory).ToString(this.entitiesByKey.Values.GetEnumerator()); /////dies here
    }
}


Full stack trace of any exception that occurs:
System.Exception: Service Name:
'....Form.GetFormDefinitionVersionByReferenceNumberFullService' ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
at System.Collections.Hashtable.HashtableEnumerator.MoveNext()
at NHibernate.Impl.Printer.ToString(IEnumerator enumerator)
at NHibernate.Impl.SessionImpl.FlushEverything()
at NHibernate.Impl.SessionImpl.AutoFlushIfRequired(ISet querySpaces)
at NHibernate.Impl.SessionImpl.GetQueries(String query, Boolean scalar)
at NHibernate.Impl.SessionImpl.Find(String query, QueryParameters parameters, IList results)
at NHibernate.Impl.SessionImpl.Find(String query, QueryParameters parameters)
at NHibernate.Impl.QueryImpl.List()
at NHibernate.Impl.AbstractQueryImpl.UniqueResult()
at NHibernate.Impl.AbstractQueryImpl.UniqueResult[T]()
at ...Form.GetFormDefinitionVersionByReferenceNumberFull.RetrieveFormDefinitionVersionByReferenceNumber(Int32 referenceNumber, AppSession appSession) in D:\...GetFormDefinitionVersionByReferenceNumberFull.cs:line 44


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 11, 2009 5:39 am 
Newbie

Joined: Tue Jul 29, 2008 5:11 am
Posts: 5
I am having the exact same problem in NH 2.0.1. If I disable log4net it works but if it is enabled to print SQL statements then Flush() fails with exception Collection was modified.

Did you find any solution to this problem? Is it a bug in NH?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 11, 2009 5:49 am 
Newbie

Joined: Tue Jul 29, 2008 5:11 am
Posts: 5
After some digging I found that this is reported as a Jira bug NH-1597. You will find it here:

http://nhjira.koah.net/browse/NH-1597


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

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.