nhibernate - GenericADOException:无法执行查询

时间:2016-01-13 00:28:16

标签: c# nhibernate mapping

有时会发生这种情况,执行某个查询时会出现错误:

GenericADOException: could not execute query [my query] --->
System.IndexOutOfRangeException: Probable I/O race condition detected while copying memory ...

我注意到在我们的nhibernate XML映射中,我们在类中有一个虚拟字段,它在映射中缺失,并且不存在于数据库中。

是否可能导致此问题?

从类似的问题我注意到这个错误可能是由于在线程之间共享会话或重复字段定义引起的,但似乎并非如此。

Approval.hbm.xml

<hibernate-mapping xmlns="urn.nhibernate-mapping-2.2"
    namespace="..." assembly="...">

    <class name="Approval" table="...">
        <composite-id name="ID" class="ApprovalId">
            <key-property name="FirstID" column="FIRST_ID"/>
            <key-property name="SecondID" column="SECOND_ID"/>
        </composite-id>
        <property name="FieldA">
            <column name="FIELD_A"/>
        </property>
        <property name="FieldB">
            <column name="FIELD_B"/>
        </property>
        <property name="FieldC">
            <column name="FIELD_C"/>
        </property>
    </class>
</hibernate-mapping>

Approval.cs

public class Approval
{
    public virtual ApprovalID ID { get; set; }
    public virtual string FieldA { get; set; }
    public virtual string FieldB { get; set; }
    public virtual string FieldC{ get; set; }
    public virtual string FieldD { get; set; }
}

ApprovalID.cs

public class ApprovalId
{
    public virtual string FirstID { get; set; }
    public virtual int SecondID { get; set; }
    public override bool Equals(object obj) { ... }
    public override int GetHashCode() { ... }
}

数据库中的表格

FIRST_ID   VARCHAR2(100)    NOT NULL
SECOND_ID  NUMBER           NOT NULL
FIELD_A    VARCHAR2(100)    NOT NULL
FIELD_B    VARCHAR2(100)    NOT NULL
FIELD_C    VARCHAR2(100)    

请注意,地图和表格没有FIELD_D

查询

using (var session = factory.CreateSession())
{
    var x = ...
    var approvalQuery = from dbApproval in session.query<Approval>()
                        where dbApproval.ID.FirstID == x.FirstId &&
                              dbApproval.ID.SecondID == x.SecondId
                        select dbApproval;

    Approval oldApproval = approvalQuery.FirstOrDefault();
}

0 个答案:

没有答案