Do it in ram using a Dictionary<TK,TV> instead get the instance from NH
(instead have a PersistentGenericMap).Let me know which is the result.

If you need a thread safe dictionary you can us a IUserCollectionType and
wrap the Dictionary with our
ThreadSafeDictionary<TKey, TValue>
To test it you can use our
MultiThreadRunner<T>

2009/10/18 Marcel <[email protected]>

>
> 5 threads create each 50 Child objects and adds, gets and removes them
> from a Parent Dictionary.
> A KeyNotFoundException occurs _sometimes_ when getting a Child.
> The KeyNotFoundException does not occur when only adding and getting
> (not removing)
> Reproducible in NHibernate 2.0.1GA, 2.1.0GA and trunk.
> With and without lazy loading.
> Is there a bug in my code or NHibernate?
>
> Thanks,
> Marcel
>
> Code for each thread:
>
> for (Int32 iterationIndex = 0; iterationIndex < iterationCount;
> iterationIndex++)
> {
>    int key = (threadIndex * 100) + iterationIndex;
>
>    // Add new Child to Parent
>    ISession session1 = sessionManager.SessionFactory.OpenSession();
>    ITransaction transaction1 = session1.BeginTransaction();
>
>    Parent parent1 = session1.Get<Parent>(1L);
>    Child child1 = new Child();
>    parent1.Childs.Add(key, child1);
>
>    transaction1.Commit();
>    session1.Close();
>
>    // Get Child from Parent
>    ISession session2 = sessionManager.SessionFactory.OpenSession();
>    ITransaction transaction2 = session2.BeginTransaction();
>
>    Parent parent2 = session2.Get<Parent>(1L);
>    Child child2 = parent2.Childs[key]; ----------->>>>>>>>>>>>>>
> KeyNotFoundException  (sometimes)
>
>    transaction2.Commit();
>    session2.Close();
>
>    // Remove Child from Parent
>    ISession session3 = sessionManager.SessionFactory.OpenSession();
>    ITransaction transaction3 = session3.BeginTransaction();
>
>    Parent parent3 = session3.Get<Parent>(1L);
>    parent3.Childs.Remove(key);
>
>    transaction3.Commit();
>    session3.Close();
> }
>
> Mapping:
>
> <class name="Parent">
>    <id name="Id">
>      <generator class="assigned"/>
>    </id>
>    <map name="Childs" cascade="save-update" optimistic-lock="false"
> lazy="false">
>      <key column="ParentId"/>
>      <index column="ParentIndex" type="int"/>
>      <one-to-many class="Child"/>
>    </map>
>  </class>
>
>  <class name="Child">
>    <id name="Id">
>      <generator class="native" />
>    </id>
>    <version name="Version" />
>  </class>
>
> Exception:
>
> System.Collections.Generic.KeyNotFoundException was unhandled
>  Message="The given key was not present in the dictionary."
>  Source="mscorlib"
>  StackTrace:
>       at System.ThrowHelper.ThrowKeyNotFoundException()
>       at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
>       at
>
> NHibernate.Collection.Generic.PersistentGenericMap`2.System.Collections.Generic.IDictionary<TKey,TValue>.get_Item
> (TKey key)
>       at
> NHibernateConcurrencyStressTest.ConcurrencyTest.ThreadContainer.Test()
>       at System.Threading.ThreadHelper.ThreadStart_Context(Object
> state)
>       at System.Threading.ExecutionContext.Run(ExecutionContext
> executionContext, ContextCallback callback, Object state)
>       at System.Threading.ThreadHelper.ThreadStart()
>
> >
>


-- 
Fabio Maulo

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