You are right, but I dont think thats related to this problem. Unfortunately, this issue is happening only in production and we cannot lower the level from Debug. Even if we did, I assume the problem would stop as it would not execute the Printer.toString() where its failing. I have taken a backup of the production database, restored it locally - made sure that the Nhibernate debugging level is "DEBUG" but have not been able to replicate the issue. I am abt to create a new session for each hit to the database...do u think that will help? could it be that using the same session for all my queries to the database is causing this issue somehow?
On Nov 11, 6:23 pm, "Jon Palmer" <[EMAIL PROTECTED]> wrote: > Yes AddEntityCriteria is called inside a loop but lastExpression is a local > variable to the AddEntityCriteria method so its initialized to null every > time AddEntityCriteria is called. So I don't see how the else part of the > check ever fires. (not sure that any of that is relevant to the problem). > > If you turn down the NHibernate debugging level to lower than Debug so that > the SessionImpl code you pasted doesn't get called do you still get the > problem? > > > > -----Original Message----- > From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Jatin > Sent: Monday, November 10, 2008 9:11 PM > To: nhusers > Subject: [nhusers] Re: System.InvalidOperationException. Collection was > modified; enumeration operation may not execute > > If you have a look, the AddEntityCriteria() is called from within a > for loop i.e. foreach (List<int?> entityIds in > collectionOfEntityIdsPerParameterLimitByEntityType[entityType]) > { > ----- > AddEntityCriter(); > ---- > } > > The reason is I want to OR the entitycriteria generated for each > List<int?> entityIds. Does that help? by the way, it works just fine, > but fails at following NHIbernate code in FlushEverything() in > SessionImpl.cs: > > if (log.IsDebugEnabled) > { > log.Debug("Flushed: " + > insertions.Count + " insertions, " + > updates.Count + " updates, " + > deletions.Count + " deletions to " + > entityEntries.Count + " objects"); > log.Debug("Flushed: " + > collectionCreations.Count + " > (re)creations, " + > collectionUpdates.Count + " > updates, " + > collectionRemovals.Count + " > removals to " + > collectionEntries.Count + " > collections"); > > new > Printer(factory).ToString(entitiesByKey.Values.GetEnumerator()); // > FAILS HERE > } > > On Nov 11, 6:04 pm, "Jon Palmer" <[EMAIL PROTECTED]> wrote: > > I;m missing something how is lastExpression ever not null when you do this > > check: > > > if (lastExpression == null) > > { > > lastExpression = entityExpression; > > } > > > Jon > > > -----Original Message----- > > From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Jatin > > Sent: Monday, November 10, 2008 9:00 PM > > To: nhusers > > Subject: [nhusers] Re: System.InvalidOperationException. Collection was > > modified; enumeration operation may not execute > > > This is the overloaded version with what you wanted. sorry for the > > confusion: > > > private void AddEntityCriteria(ICriteria parentCriteria, string > > alias, string entityType, List<int?> entities) > > { > > if (entities.Count > 1) > > { > > string setAlias = "ASI"; > > ICriteria entityCriteria = > > parentCriteria.CreateCriteria( > > string.Format("{0}.{1}", alias, > > enumAttributeInstance.AttributeSetInstance), setAlias, > > JoinType.InnerJoin); > > > NHibernate.Expression.AbstractCriterion lastExpression > > = null; > > > NHibernate.Expression.AbstractCriterion > > entityExpression = GetEntityExpression(setAlias, entityType, > > entities); > > if (lastExpression == null) > > { > > lastExpression = entityExpression; > > } > > else > > { > > lastExpression = > > NHibernate.Expression.Expression.Or(lastExpression, entityExpression); > > } > > > entityCriteria.Add(lastExpression); > > } > > else if (entities.Count > 0) > > { > > int? entityId = entities[0]; > > AddEntityCriteria(parentCriteria, alias, entityType, > > entityId); > > } > > > } > > > On Nov 11, 5:57 pm, Jatin <[EMAIL PROTECTED]> wrote: > > > Hi Jon, > > > > This is from my original post. As you can see it has 3 parameters. > > > Could you send me source code where you see AddEntityCriteria with one > > > parameter. Thanks > > > > // Add Entity Crieria > > > if (entityIds != null) > > > { > > > AddEntityCriteria(criteria, alias, > > > entityType, entityIds); > > > } > > > > On Nov 11, 5:51 pm, "Jon Palmer" <[EMAIL PROTECTED]> wrote: > > > > > From your original post it looks like there is a version of > > > > AddEntityCriteria that takes a List<int?> as a parameter. > > > > > -----Original Message----- > > > > From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of > > > > Jatin > > > > Sent: Monday, November 10, 2008 8:46 PM > > > > To: nhusers > > > > Subject: [nhusers] Re: System.InvalidOperationException. Collection was > > > > modified; enumeration operation may not execute > > > > > Hi Jon > > > > > Here is the AddEntityCriteria() source code.Pl let me know if u need > > > > any more info. Thanks > > > > > private void AddEntityCriteria(ICriteria parentCriteria, string alias, > > > > string entityTypeName, int? entityId) > > > > { > > > > if (!string.IsNullOrEmpty(entityTypeName) || > > > > entityId.HasValue) > > > > { > > > > string setAlias = "ASI"; > > > > ICriteria entityCriteria = > > > > parentCriteria.CreateCriteria( > > > > string.Format("{0}.{1}", alias, > > > > enumAttributeInstance.AttributeSetInstance), setAlias, > > > > JoinType.InnerJoin); > > > > > if (!string.IsNullOrEmpty(entityTypeName)) > > > > { > > > > entityCriteria.Add(new > > > > NHibernate.Expression.EqExpression( > > > > string.Format("{0}.{1}", setAlias, > > > > enumAttributeSetInstance.EntityTypeName), entityTypeName)); > > > > } > > > > if (entityId.HasValue) > > > > { > > > > entityCriteria.Add(new > > > > NHibernate.Expression.EqExpression( > > > > string.Format("{0}.{1}", setAlias, > > > > enumAttributeSetInstance.EntityId), entityId.Value)); > > > > } > > > > } > > > > } > > > > > On Nov 11, 5:38 pm, "Jon Palmer" <[EMAIL PROTECTED]> wrote: > > > > > What does AddEntityCriteria look like and how does it use the > > > > > entryIds? > > > > > > -----Original Message----- > > > > > From: [email protected] [mailto:[EMAIL PROTECTED] On > > > > > > Behalf Of Jatin > > > > > Sent: Monday, November 10, 2008 6:38 PM > > > > > To: nhusers > > > > > Subject: [nhusers] System.InvalidOperationException. Collection was > > > > > modified; enumeration operation may not execute > > > > > > Hi All > > > > > > I get the following exception when using Criteria objects in > > > > > NHibernate. The error is only coming up in production and not in Dev > > > > > or UAT. I am stumped as cant replicate the error and need to fix this > > > > > asap. The error and the code resulting in the error are below. Any > > > > > help will be greatly appreciated. I am hitting the database multiple > > > > > times with the same Nhibernate session. Is that the problem. Thanks > > > > > Jatin. > > > > > > The error : > > > > > > Base exception: > > > > > System.InvalidOperationException > > > > > Collection was modified; enumeration operation may not execute. > > > > > > Stack Trace: > > > > > 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.Find(CriteriaImpl criteria, IList > > > > > results) > > > > > at NHibernate.Impl.SessionImpl.Find[T](CriteriaImpl criteria) > > > > > at NHibernate.Impl.CriteriaImpl.List[T]() > > > > > at > > > > > GrantEd.UtilityServices.ExtendedAttribute.AttributeInstancePathEvaluator > > > > > .InternalEvaluate(List`1 > > > > > entities) in C:\UserData\SEMISPT\Source\Development\UtilityServices > > > > > \ExtendedAttribute\GrantEd.UtilityServices.ExtendedAttribute\Controller > > > > > \AttributeInstancePathEvaluator.cs:line 121 > > > > > > The piece of code that results in the error: > > > > > > public IAttributeInstances InternalEvaluate(List<KeyValuePair<string, > > > > > int?>> entities) > > > > > { > > > > > IAttributeInstances attributeInstances = new > > > > > AttributeInstances(); > > > > > using (ISession session = > > > > > NHibernateSessionManager.Instance.GetSession<AttributeInstance>(_session > > > > > )) > > > > > { > > > > > // Based on List<KeyValuePair<string, int?>> of > > > > > entities, Get a list per parameter limit > > > > > //(1000 parameters for an IN condition) of List<int?> > > > > > entityIds. > > > > > Dictionary<string, List<List<int?>>> > > > > > collectionOfEntityIdsPerParameterLimitByEntityType = > > > > > GetCollectionOfEntityIdsPerParameterLimitByEntityType(entities); > > > > > > string alias = "E"; > > > > > > // In case no entities provided, still need to return > > > > > records matching > > > > > // AttributePath > > > > > > > ... > > read more »- Hide quoted text - > > - Show quoted text - --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
