NHibernate未映射的类异常

时间:2010-03-23 00:49:42

标签: nhibernate nhibernate-mapping

我正在尝试使用NHibernate 2.1.2实现一对多关系,但不断获得“关联引用未映射类”异常。我已经验证我的hbm.xml文件是嵌入式资源。这是我的类和映射。有什么想法吗?

public class OrderStatus
{
    public virtual decimal MainCommit { get; set; }
    public virtual decimal CommitNumber { get; set; }
    public virtual string InvoiceNumber { get; set; }
    public virtual string ShipTo { get; set; }
    public virtual string CustomerOrderNumber { get; set; }
    public virtual string Station { get; set; }
    public virtual DateTime RequestedShipDate { get; set; }
    public virtual decimal EstimatedValue { get; set; }
    public virtual decimal EstimatedWeight { get; set; }
    public virtual string Customer { get; set; }
    public virtual DateTime InvoiceDate { get; set; }
    public virtual ICollection<Promise> Promises { get; set; }
}

<class name="AladdinDb.Models.OrderStatus, AladdinDb" table="vorder_status">
    <id name="CommitNumber" type="decimal" column="commit_no">
        <generator class="assigned">
            <param name="property">
                Plan
            </param>
        </generator>
    </id>
    <property name="MainCommit" column="main_commit" type="decimal" />
    <property name="InvoiceNumber" column="invoice_no" type="string" />
    <property name="ShipTo" column="ship_to" type ="string"/>
    <property name="CustomerOrderNumber" column="cust_order_no" type="string" />
    <property name="Station" column="station" type="string" />
    <property name="RequestedShipDate" column="req_ship_date" type="DateTime" />
    <property name="EstimatedValue" column="estimated_value" type="decimal"/>
    <property name="EstimatedWeight" column="estimated_weight" type="decimal" />
    <property name="Customer" column="customer" type="string" />
    <property name="InvoiceDate" column="invoice_date" />
    <set name="Promises">
        <key column="commit_no"></key>
        <one-to-many class="Promise" />
    </set>
</class>

public class Promise
{
    public virtual decimal CommitNumber { get; set; }
    public virtual DateTime PromiseDate { get; set; }
    public virtual string WhoAsked { get; set; }
    public virtual string WhoGave { get; set; }
    public virtual string Iffy { get; set; }
}

<class name="AladdinDb.Models.Promise, AladdinDb" table="promise">
    <id name="CommitNumber" type="decimal" column="commit_no">
        <generator class="assigned" />
    </id>
    <property name="PromiseDate" column="promise_date" />
    <property name="WhoAsked" column="who_asked" />
    <property name="WhoGave" column="who_gave" />
    <property name="Iffy" column="iffy" />
</class>

2 个答案:

答案 0 :(得分:3)

您需要在关联中使用完全限定的类名,就像在类映射中一样。

如果您想使用不合格的类名,请使用assembly元素上的namespacehibernate-mapping属性。

<set name="Promises">
    <key column="commit_no" />
    <one-to-many class="AladdinDb.Models.Promise, AladdinDb" />
</set>

答案 1 :(得分:1)

在OrderStatus中 在课堂上

public virtual Promise Promise{ get; set; }

中的映射

<many-to-one name="Promise" fetch="join" column="Promise" />

Promise类中的任何内容或关于此的映射。