2010-03-23 222 views
1

我想使用NHibernate 2.1.2實現一對多關係,但不斷得到「關聯引用未映射類」異常。我已驗證我的hbm.xml文件是嵌入式資源。這裏是我的類和映射。有任何想法嗎?NHibernate未映射類異常

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> 

回答

3

您需要在關聯中使用完全限定的類名,就像在類映射中一樣。

如果要使用非限定類名,請在hibernate-mapping元素上使用assemblynamespace屬性。

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

Grrr。我曾嘗試過「完全合格」,但忽略了模型。在某種程度上,我想我會犯新手錯誤。謝謝!! – 2010-03-23 14:31:30

1

在OrderStatus 在類

public virtual Promise Promise{ get; set; } 

在映射

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

沒有在承諾類或映射這個問題。

+0

在我看來,這個答案逆轉了我的關係。一個OrderStatus可以有0個或更多的Promise行。 – 2010-03-23 14:24:47