views:

70

answers:

2

I am trying to implement a one-to-many relationship using NHibernate 2.1.2 but keep getting "Association references unmapped class" exceptions. I have verified that my hbm.xml files are embedded resource. Here are my classes and mappings. Any ideas?

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>
+1  A: 

In OrderStatus in the class

public virtual Promise Promise{ get; set; }

in the mapping

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

nothing in the Promise class or mapping about this.

Kris-I
It appears to me that this answer reverses my relationship. There can be 0 or more Promise rows for a single OrderStatus.
John Prideaux
+2  A: 

You need to use the fully qualified classname in the association, just as in your class mappings.

Use the assembly and namespace attributes on the hibernate-mapping element if you want to use unqualified class names.

<set name="Promises">
    <key column="commit_no" />
    <one-to-many class="AladdinDb.Models.Promise, AladdinDb" />
</set>
Lachlan Roche
Grrr. I had tried "fully qualified" but left out Models. At some point, I suppose I'll quite making newbie mistakes. Thanks!!
John Prideaux