NHibernate的FieldNameLookup抛出IndexOutOfRangeException [英] Nhibernate FieldNameLookup throws IndexOutOfRangeException

查看:263
本文介绍了NHibernate的FieldNameLookup抛出IndexOutOfRangeException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好 时不时地,我们得到了这个非常奇怪的错误

Hello everyone Every now and then we get this very weird error

NHibernate.ADOException:无法执行查询 [选择this_.Id为Id37_0_,this_.AREA_ID为AREA2_37_0_,this_.BAT_CHK为BAT3_37_0_,this_.BAT_COD为BAT4_37_0_,this_.BBEACT为BBEACT37_0_,this_.CREDATE为CREDATE37_0_,this_.DEST_LOC为DEST7_37_0_,this_.DOCNR为DOCNR37_0_, this_.DOCTYPE为DOCTYPE37_0_,this_.DUTY_STATUS为DUTY10_37_0_,this_.EAN为EAN37_0_,this_.EXCEPTION_REASON为EXCEPTION12_37_0_,this_.ERROR_TEXT为ERROR13_37_0_,this_.FLOWTYPE为FLOWTYPE37_0_,this_.GOODS_STATUS为GOODS15_37_0_,this_.INSERT_DATETIME为INSERT16_37_0_,THIS_。 MATNR为MATNR37_0_,this_.MVTTYPE为MVTTYPE37_0_,this_.ORDNR为ORDNR37_0_,this_.PACK_ID为PACK20_37_0_,this_.PALNR为PALNR37_0_,this_.PRDACT为PRDACT37_0_,this_.QTYLOAD为QTYLOAD37_0_,this_.SCANNR为SCANNR37_0_,this_.SEQ作为SEQ37_0_,this_.SOURCE_LOC为SOURCE26_37_0_,this_.STATUS为STATUS37_0_,this_.TEXT为TEXT37_0_,this_.USER_ID为USER29_37_0_,this_.WH_ID作为WH30_37_0_从ZZHTR_RCV THIS_ WHERE this_.DOCNR =?和this_.ORDNR =?和this_.MVTTYPE =?和this_.WH_ID =? ] 位置参数:#0> 10972365 / O#0> 1300196311#0> 0#0> NL02 [SQL:SELECT this_.Id为Id37_0_,this_.AREA_ID为AREA2_37_0_,this_.BAT_CHK为BAT3_37_0_,this_.BAT_COD为BAT4_37_0_,this_.BBEACT为BBEACT37_0_,this_.CREDATE为CREDATE37_0_,this_.DEST_LOC为DEST7_37_0_,this_.DOCNR作为DOCNR37_0_,this_.DOCTYPE为DOCTYPE37_0_,this_.DUTY_STATUS为DUTY10_37_0_,this_.EAN为EAN37_0_,this_.EXCEPTION_REASON为EXCEPTION12_37_0_,this_.ERROR_TEXT为ERROR13_37_0_,this_.FLOWTYPE为FLOWTYPE37_0_,this_.GOODS_STATUS为GOODS15_37_0_,this_.INSERT_DATETIME为INSERT16_37_0_, this_.MATNR为MATNR37_0_,this_.MVTTYPE为MVTTYPE37_0_,this_.ORDNR为ORDNR37_0_,this_.PACK_ID为PACK20_37_0_,this_.PALNR为PALNR37_0_,this_.PRDACT为PRDACT37_0_,this_.QTYLOAD为QTYLOAD37_0_,this_.SCANNR为SCANNR37_0_,THIS_。序列为SEQ37_0_,this_.SOURCE_LOC为SOURCE26_37_0_,this_.STATUS为STATUS37_0_,this_.TEXT为TEXT37_0_,this_.USER_ID为USER29_37_0_,this_.WH_ID作为WH30_37_0_从ZZHTR_RCV THIS_ WHERE this_.DOCNR =?和this_.ORDNR =?和this_.MVTTYPE =? ?和this_.WH_ID =] ---> System.IndexOutOfRangeException:Id37_0_    在System.Data.ProviderBase.FieldNameLookup.GetOrdinal(字符串字段名)    在System.Data.SqlClient.SqlDataReader.GetOrdinal(字符串名称)    在NHibernate.Driver.NHybridDataReader.GetOrdinal(字符串名称)    在NHibernate.Type.NullableType.NullSafeGet(IDataReader的RS,字符串名称)    在NHibernate.Type.NullableType.NullSafeGet(IDataReader的RS,的String []的名称,ISessionImplementor会议,对象所有者)    在NHibernate.Loader.Loader.GetKeyFromResultSet(的Int32我,IEntityPersister持留,对象ID,IDataReader的RS,ISessionImplementor会话)    在NHibernate.Loader.Loader.GetRowFromResultSet(IDataReader的结果集,ISessionImplementor会议,QueryParameters queryParameters,lockmode可以[] lockModeArray,的EntityKey optionalObjectKey,IList的hydratedObjects,的EntityKey []键,布尔returnProxies)    在NHibernate.Loader.Loader.DoQuery(ISessionImplementor会议,QueryParameters queryParameters,布尔returnProxies)    在NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor会议,QueryParameters queryParameters,布尔returnProxies)    在NHibernate.Loader.Loader.DoList(ISessionImplementor会议,QueryParameters queryParameters)    ---内部异常堆栈跟踪的结尾---    在NHibernate.Loader.Loader.DoList(ISessionImplementor会议,QueryParameters queryParameters)    在NHibernate.Loader.Loader.ListIgnoreQueryCache(ISessionImplementor会议,QueryParameters queryParameters)    在NHibernate.Loader.Loader.List(ISessionImplementor会议,QueryParameters queryParameters,的ISet 1 querySpaces,ITYPE [] resultTypes)    在NHibernate.Loader.Criteria.CriteriaLoader.List(ISessionImplementor会话)    在NHibernate.Impl.SessionImpl.List(CriteriaImpl标准,IList的结果)    在NHibernate.Impl.CriteriaImpl.List(IList的结果)    在NHibernate.Impl.CriteriaImpl.List [T]()    在Rhino.Commons.RepositoryImplBase 1.FindAll(的DetachedCriteria标准,令[]订单)    在Rhino.Commons.Repository`1.FindAll(的DetachedCriteria标准,令[]命令)

NHibernate.ADOException: could not execute query [ SELECT this_.Id as Id37_0_, this_.AREA_ID as AREA2_37_0_, this_.BAT_CHK as BAT3_37_0_, this_.BAT_COD as BAT4_37_0_, this_.BBEACT as BBEACT37_0_, this_.CREDATE as CREDATE37_0_, this_.DEST_LOC as DEST7_37_0_, this_.DOCNR as DOCNR37_0_, this_.DOCTYPE as DOCTYPE37_0_, this_.DUTY_STATUS as DUTY10_37_0_, this_.EAN as EAN37_0_, this_.EXCEPTION_REASON as EXCEPTION12_37_0_, this_.ERROR_TEXT as ERROR13_37_0_, this_.FLOWTYPE as FLOWTYPE37_0_, this_.GOODS_STATUS as GOODS15_37_0_, this_.INSERT_DATETIME as INSERT16_37_0_, this_.MATNR as MATNR37_0_, this_.MVTTYPE as MVTTYPE37_0_, this_.ORDNR as ORDNR37_0_, this_.PACK_ID as PACK20_37_0_, this_.PALNR as PALNR37_0_, this_.PRDACT as PRDACT37_0_, this_.QTYLOAD as QTYLOAD37_0_, this_.SCANNR as SCANNR37_0_, this_.SEQ as SEQ37_0_, this_.SOURCE_LOC as SOURCE26_37_0_, this_.STATUS as STATUS37_0_, this_.TEXT as TEXT37_0_, this_.USER_ID as USER29_37_0_, this_.WH_ID as WH30_37_0_ FROM ZZHTR_RCV this_ WHERE this_.DOCNR = ? and this_.ORDNR = ? and this_.MVTTYPE = ? and this_.WH_ID = ? ] Positional parameters: #0>10972365/O #0>1300196311 #0>O #0>NL02 [SQL: SELECT this_.Id as Id37_0_, this_.AREA_ID as AREA2_37_0_, this_.BAT_CHK as BAT3_37_0_, this_.BAT_COD as BAT4_37_0_, this_.BBEACT as BBEACT37_0_, this_.CREDATE as CREDATE37_0_, this_.DEST_LOC as DEST7_37_0_, this_.DOCNR as DOCNR37_0_, this_.DOCTYPE as DOCTYPE37_0_, this_.DUTY_STATUS as DUTY10_37_0_, this_.EAN as EAN37_0_, this_.EXCEPTION_REASON as EXCEPTION12_37_0_, this_.ERROR_TEXT as ERROR13_37_0_, this_.FLOWTYPE as FLOWTYPE37_0_, this_.GOODS_STATUS as GOODS15_37_0_, this_.INSERT_DATETIME as INSERT16_37_0_, this_.MATNR as MATNR37_0_, this_.MVTTYPE as MVTTYPE37_0_, this_.ORDNR as ORDNR37_0_, this_.PACK_ID as PACK20_37_0_, this_.PALNR as PALNR37_0_, this_.PRDACT as PRDACT37_0_, this_.QTYLOAD as QTYLOAD37_0_, this_.SCANNR as SCANNR37_0_, this_.SEQ as SEQ37_0_, this_.SOURCE_LOC as SOURCE26_37_0_, this_.STATUS as STATUS37_0_, this_.TEXT as TEXT37_0_, this_.USER_ID as USER29_37_0_, this_.WH_ID as WH30_37_0_ FROM ZZHTR_RCV this_ WHERE this_.DOCNR = ? and this_.ORDNR = ? and this_.MVTTYPE = ? and this_.WH_ID = ?] ---> System.IndexOutOfRangeException: Id37_0_ at System.Data.ProviderBase.FieldNameLookup.GetOrdinal(String fieldName) at System.Data.SqlClient.SqlDataReader.GetOrdinal(String name) at NHibernate.Driver.NHybridDataReader.GetOrdinal(String name) at NHibernate.Type.NullableType.NullSafeGet(IDataReader rs, String name) at NHibernate.Type.NullableType.NullSafeGet(IDataReader rs, String[] names, ISessionImplementor session, Object owner) at NHibernate.Loader.Loader.GetKeyFromResultSet(Int32 i, IEntityPersister persister, Object id, IDataReader rs, ISessionImplementor session) at NHibernate.Loader.Loader.GetRowFromResultSet(IDataReader resultSet, ISessionImplementor session, QueryParameters queryParameters, LockMode[] lockModeArray, EntityKey optionalObjectKey, IList hydratedObjects, EntityKey[] keys, Boolean returnProxies) at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) at NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters) --- End of inner exception stack trace --- at NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters) at NHibernate.Loader.Loader.ListIgnoreQueryCache(ISessionImplementor session, QueryParameters queryParameters) at NHibernate.Loader.Loader.List(ISessionImplementor session, QueryParameters queryParameters, ISet1 querySpaces, IType[] resultTypes) at NHibernate.Loader.Criteria.CriteriaLoader.List(ISessionImplementor session) at NHibernate.Impl.SessionImpl.List(CriteriaImpl criteria, IList results) at NHibernate.Impl.CriteriaImpl.List(IList results) at NHibernate.Impl.CriteriaImpl.List[T]() at Rhino.Commons.RepositoryImplBase1.FindAll(DetachedCriteria criteria, Order[] orders) at Rhino.Commons.Repository`1.FindAll(DetachedCriteria criteria, Order[] orders)

的问题是,该错误是不是每次都显示出来。我看到它的Id列,但不明白为什么它是有问题存在。 我是pretty的确定的映射是确定

The problem is that this error is not showing up every time. I see it's the Id column, but don't understand why it is having issues there. I'm pretty sure the mapping is OK

映射:

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                   assembly="XX.Business"
                   namespace="XX.Business"
                   default-lazy="true">
  <class name="XX.Business.Receive, XX.Business" table="ZZHTR_RCV" lazy="true">
    <id name="Id" type="int">
      <generator class="identity" />
    </id>
    <property name="AreaCode" column="AREA_ID"/>
    <property name="BatchCheck" column="BAT_CHK"/>
    <property name="BatchCode" column="BAT_COD"/>
    <property name="BbeAct" column="BBEACT"/>
    <property name="CreationDate" column="CREDATE" not-null="true"/>
    <property name="DestinationLocation" column="DEST_LOC"/>
    <property name="DocNr" column="DOCNR"/>
    <property name="DocType" column="DOCTYPE"/>
    <property name="DutyStatus" column="DUTY_STATUS"/>
    <property name="Ean" column="EAN"/>
    <property name="ExceptionReason" column="EXCEPTION_REASON"/>
    <property name="ErrorText" column="ERROR_TEXT"/>
    <property name="FlowType" column="FLOWTYPE"/>
    <property name="GoodsStatus" column="GOODS_STATUS"/>
    <property name="InsertDateTime" column="INSERT_DATETIME" not-null="true"/>
    <property name="MaterialNr" column="MATNR"/>
    <property name="MovementType" column="MVTTYPE"/>
    <property name="OrderNr" column="ORDNR"/>
    <property name="ManufacturingBatch" column="PACK_ID"/>
    <property name="PalletNr" column="PALNR"/>
    <property name="ProdAct" column="PRDACT"/>
    <property name="QuantityLoad" column="QTYLOAD"/>
    <property name="ScanNr" column="SCANNR"/>
    <property name="Sequence" column="SEQ"/>
    <property name="SourceLocation" column="SOURCE_LOC"/>
    <property name="Status" column="STATUS"/>
    <property name="Text" column="TEXT"/>
    <property name="UserId" column="USER_ID"/>
    <property name="WarehouseCode" column="WH_ID"/>


  </class>
</hibernate-mapping>

类:

[XmlRoot("ZZHTR_RCV")]
    public class Receive : DomainObject
    {
        [XmlElement("AREA_ID")]
        public virtual string AreaCode { get; set; }
        [XmlElement("BAT_CHK")]
        public virtual string BatchCheck { get; set; }
        [XmlElement("BAT_COD")]
        public virtual string BatchCode { get; set; }
        [XmlElement("BBEACT")]
        public virtual DateTime? BbeAct { get; set; }
        [XmlElement("CREDATE")]
        public virtual DateTime CreationDate { get; set; }
        [XmlElement("DEST_LOC")]
        public virtual string DestinationLocation { get; set; }
        [XmlElement("DOCNR")]
        public virtual string DocNr { get; set; }
        [XmlElement("DOCTYPE")]
        public virtual string DocType { get; set; }
        [XmlElement("DUTY_STATUS")]
        public virtual DutyStatus DutyStatus { get; set; }
        [XmlElement("EAN")]
        public virtual string Ean { get; set; }
        [XmlElement("ERROR_TEXT")]
        public virtual string ErrorText { get; set; }
        [XmlElement("FLOWTYPE")]
        public virtual string FlowType { get; set; }
        [XmlElement("GOODS_STATUS")]
        public virtual GoodsStatus GoodsStatus { get; set; }
        [XmlElement("INSERT_DATETIME")]
        public virtual DateTime InsertDateTime { get; set; }
        [XmlElement("MATNR")]
        public virtual string MaterialNr { get; set; }
        [XmlElement("MVTTYPE")]
        public virtual string MovementType { get; set; }
        [XmlElement("ORDNR")]
        public virtual string OrderNr { get; set; }
        [XmlElement("PACK_ID")]
        public virtual string ManufacturingBatch { get; set; }
        [XmlElement("PALNR")]
        public virtual string PalletNr { get; set; }
        [XmlElement("PRDACT")]
        public virtual DateTime? ProdAct { get; set; }
        [XmlElement("QTYLOAD")]
        public virtual int QuantityLoad { get; set; }
        [XmlElement("SCANNR")]
        public virtual string ScanNr { get; set; }
        [XmlElement("SEQ")]
        public virtual int Sequence { get; set; }
        [XmlElement("SOURCE_LOC")]
        public virtual string SourceLocation { get; set; }
        [XmlElement("STATUS")]
        public virtual MobileProcessingStatus Status { get; set; }
        [XmlElement("TEXT")]
        public virtual string Text { get; set; }
        [XmlElement("USER_ID")]
        public virtual string UserId { get; set; }
        [XmlElement("WH_ID")]
        public virtual string WarehouseCode { get; set; }
        [XmlElement("EXCEPTION_REASON")]
        public virtual ExceptionReason ExceptionReason { get; set; }
        public virtual string Prodline
        {
            get
            {
                if(string.IsNullOrEmpty(this.PalletNr) || !this.PalletNr.Length.Equals(18))
                {
                    return "000";
                }
                else
                {
                    return this.PalletNr.Substring(8, 3);
                }
            }
        }
        public virtual string EERPProcessOrder { get; set; }

    }

id是从domainObject的继承:

Id is inherited from DomainObject:

public abstract class DomainObject:IDomainObject
    {
        [DataMember]
        public virtual int Id { get; set; }

表:

[Id] [int] IDENTITY(1,1) NOT NULL,
    [AREA_ID] [nvarchar](255) NOT NULL,
    [BAT_CHK] [nvarchar](255) NULL,
    [BAT_COD] [nvarchar](255) NULL,
    [BBEACT] [datetime] NULL,
    [CREDATE] [datetime] NOT NULL,
    [DEST_LOC] [nvarchar](255) NULL,
    [DOCNR] [nvarchar](255) NOT NULL,
    [DOCTYPE] [nchar](2) NOT NULL,
    [DUTY_STATUS] [int] NOT NULL,
    [EAN] [nvarchar](255) NOT NULL,
    [ERROR_TEXT] [nvarchar](255) NULL,
    [EXCEPTION_REASON] [int] NULL,
    [FLOWTYPE] [nvarchar](255) NULL,
    [GOODS_STATUS] [int] NOT NULL,
    [INSERT_DATETIME] [datetime] NOT NULL,
    [MATNR] [nvarchar](255) NOT NULL,
    [MVTTYPE] [nchar](1) NOT NULL,
    [ORDNR] [nvarchar](255) NOT NULL,
    [PACK_ID] [nvarchar](255) NULL,
    [PALNR] [nvarchar](255) NOT NULL,
    [PRDACT] [datetime] NULL,
    [QTYLOAD] [int] NOT NULL,
    [SCANNR] [nvarchar](255) NOT NULL,
    [SEQ] [int] NOT NULL,
    [SOURCE_LOC] [nvarchar](255) NULL,
    [STATUS] [int] NOT NULL,
    [TEXT] [nvarchar](255) NULL,
    [USER_ID] [nvarchar](255) NOT NULL,
    [WH_ID] [nvarchar](255) NOT NULL,

任何人都可以帮助吗?

Can anyone help please?

推荐答案

我们 - 和其他人 - 也有这个问题,最近和过去。这似乎是与多线程访问非线程安全的的SqlConnection 。下面的很长发表包含更多的例子,在这个问题上一些细节:<一href="http://social.msdn.microsoft.com/forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9/"相对=nofollow称号=SQLDataReader.GetOrdinal()很少失败,IndexOutOfRange> SQLDataReader.GetOrdinal()与IndexOutOfRange 很少失败。有bbzippo状态:

we - and others - have also had this problem recently and in the past. It seems to be related to multi-threaded access to the non-thread-safe SqlConnection. The following really long post contains more examples and some more detail on the issue: SQLDataReader.GetOrdinal() fails rarely with IndexOutOfRange. There bbzippo states:

这是明显的是,SqlDataReader的读取   结果集遗留下来的   在相同的执行previous查询   连接几秒钟前。

"It's evident that SqlDataReader reads a result set left over from the previous query executed on the same connection a couple of seconds ago."

不幸的是,我还没有找到为什么会突然出现在code已经没有工作了一段时间的问题此异常的任何真正的解释。

Unfortunately, I haven't found any real explanation of why this exception occurs suddenly in code that has been working without a problem for some time.

有的在给定的线程提出的建议是:

Some of the suggestions made in the given thread are:

  1. 关闭连接池,让您的连接字符串看起来像如数据源= SQL2005;初始目录= MyDbName;用户ID = MyLogin;密码=为mypass;池=假(这很可能意味着性能损失为您的应用程序,但是一定要工作
  2. 在重构所有的静态 code引用您的的SqlConnection 实例(县)非静态
  3. 修正可能的多线程访问您的的SqlConnection S(这可能不是那么容易......)
  1. Turn connection pooling off, so your connection string would look like e.g. "Data Source=Sql2005;Initial Catalog=MyDbName;User Id=MyLogin;Password=MyPass;Pooling=false" (this most likely will mean a performance hit for your application but is sure to work)
  2. Refactor all static code referencing your SqlConnection instance(s) to non-static
  3. Fix possible multi-threaded access to your SqlConnections (this might not be that easy...)

我仍然试图找到我们的应用程序错误的根源,但它不是那么容易,因为我一直没能到我们的生活环境之外重现。 <一href="http://social.msdn.microsoft.com/forums/en-US/adodotnetdataproviders/thread/74a5db87-c63f-4386-b317-e848dedb2cd9/#8097bc33-ab26-49d2-b933-620adee94dae"相对=nofollow>马特Neerincx [MSFT]建议以他的答案之一在上述岗位的使用不同的连接字符串,因此不同的连接池帮助缩小问题的根源。

I'm still trying to find the source of the error in our application but it's not that easy because I haven't been able to reproduce it outside our live environment. Matt Neerincx [MSFT] suggests in one of his answers in the above mentioned post to use different connection strings and thus different connection pools for different parts of your application to help narrow down the source of the problem.

另一种读我就发现这个问题是在休眠论坛: https://开头论坛.hibernate.org / viewtopic.php?P = 2386963 ,其中一张海报也有问题,延迟加载在一个多线程的情况下。

Another read I found regarding this problem was on the hibernate forums: https://forum.hibernate.org/viewtopic.php?p=2386963, where one poster also had problems with lazy-loading in a multi-threaded scenario.

希望这将引导向正确的方向进行修复任何人。

Hope this will guide anyone in the right direction for a fix.

奥利弗

这篇关于NHibernate的FieldNameLookup抛出IndexOutOfRangeException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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