Error: "Cannot simultaneously fetch multiple bags" when calling Configuration.BuildSessionFactory();
        Posted  
        
            by Nick Meldrum
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Nick Meldrum
        
        
        
        Published on 2010-03-08T18:56:46Z
        Indexed on 
            2010/03/17
            9:31 UTC
        
        
        Read the original article
        Hit count: 375
        
We are getting this error after upgrading to NHibernate 2.1.
[QueryException: Cannot simultaneously fetch multiple bags.]
   NHibernate.Loader.BasicLoader.PostInstantiate() +418
   NHibernate.Loader.Entity.EntityLoader..ctor(IOuterJoinLoadable persister, String[] uniqueKey, IType uniqueKeyType, Int32 batchSize, LockMode lockMode, ISessionFactoryImplementor factory, IDictionary`2 enabledFilters) +123
   NHibernate.Loader.Entity.BatchingEntityLoader.CreateBatchingEntityLoader(IOuterJoinLoadable persister, Int32 maxBatchSize, LockMode lockMode, ISessionFactoryImplementor factory, IDictionary`2 enabledFilters) +263
   NHibernate.Persister.Entity.AbstractEntityPersister.CreateEntityLoader(LockMode lockMode, IDictionary`2 enabledFilters) +26
   NHibernate.Persister.Entity.AbstractEntityPersister.CreateLoaders() +57
   NHibernate.Persister.Entity.AbstractEntityPersister.PostInstantiate() +1244
   NHibernate.Persister.Entity.SingleTableEntityPersister.PostInstantiate() +18
   NHibernate.Impl.SessionFactoryImpl..ctor(Configuration cfg, IMapping mapping, Settings settings, EventListeners listeners) +3261
   NHibernate.Cfg.Configuration.BuildSessionFactory() +87
Without stepping into the NHibernate source, it doesn't look like I can see which mapping is creating the issue.
It's a very old application with a load of mappings files, lots of mappings have one-to-many bags in them, all lazy instantiated.
For example:
    <bag name="Ownership" lazy="true" cascade="all" inverse="true" outer-join="auto" where="fkOwnershipStatusID!=6">
        <key column="fkStakeHolderID"/>
        <one-to-many class="StakeholderLib.Ownership,StakeholderLib" />
    </bag>
maps to:
public virtual IList Ownership {
        get {
            if (ownership == null)
                ownership = new ArrayList();
            return ownership;
        }
        set { ownership = value; }
    }    
Has anyone seen this error before when upgrading to NHibernate 2.1?
© Stack Overflow or respective owner