错误:“无法同时提取多个包"调用Configuration.BuildSessionFactory()时; [英] Error: "Cannot simultaneously fetch multiple bags" when calling Configuration.BuildSessionFactory();

查看:147
本文介绍了错误:“无法同时提取多个包"调用Configuration.BuildSessionFactory()时;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

升级到NHibernate 2.1后,我们会收到此错误.

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

在没有进入NHibernate源代码的情况下,我似乎看不到是哪个映射导致了问题.

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.

例如:

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

映射到:

public virtual IList Ownership {
        get {
            if (ownership == null)
                ownership = new ArrayList();
            return ownership;
        }
        set { ownership = value; }
    }    

有人在升级到NHibernate 2.1之前见过此错误吗?

Has anyone seen this error before when upgrading to NHibernate 2.1?

推荐答案

我们最终找到了答案...

We found the answer eventually...

我们有一个实体,其中有一个以上的袋子,并且具有多对多关系

We had an entity that had more than 1 bag with a many to many relationship that had

outer-join="true"

设置.

这引起了错误,因为设置外部联接获取时通常这样做是为了限制db往返,从而使nHibernate能够在1个select中检索整个关联.在这种情况下,这将导致在每个袋子上进行预取,立即导致错误.

This caused the error because when you set outer-join fetching you usually do this to limit the db round-trips, enabling nHibernate to retrieve the whole association in 1 select. In this circumstance this will cause a pre-fetch on each bag immediately causing the error.

我们将其更改为"outer-join ="auto"(如下所示),并且它们不再被预取.这阻止了nHibernate尝试同时获取多个包的操作.

We changed that to outer-join="auto" (as below) and they stopped being pre-fetched. This stopped nHibernate attempting to fetch multiple bags simultaneously.

<bag name="Groups" lazy="true" cascade="none" table="dbname..tablename">
    <key column="foreignkeyname" />
        <many-to-many class="classname.typename,assemblyname"
                column="foreignkeyname" outer-join="auto" />
</bag>

这篇关于错误:“无法同时提取多个包"调用Configuration.BuildSessionFactory()时;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆