Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NHibernate: An association from the table X refers to an unmapped class: X

I have two mapping files for an order and a customer object.

Customer Mapping:

  <class name="OODB.Domain.Customer, OODB.Domain" entity-name="Customers">
     <id name="ID" column="customer_id">
      <generator class="guid" />
     </id>
     <property name="FirstName" column="first_name"/>
     <property name="LastName" column="last_name"/>
     <property name="EMail" column="email"/>
     <property name="Telephone" column="telephone" />

    <component name="Address" class="Address">
       <property name="Street" column="street"></property>
       <property name="PostalCode" column="postal_code"></property>
       <property name="City" column="city"></property>
    </component>
  </class>
 </hibernate-mapping>

Order Mapping:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="OODB.Domain"   namespace="OODB.Domain">  
  <class name="OODB.Domain.CustomerOrder, OODB.Domain" entity-name="Orders">
    <id name="ID" column="order_id">
      <generator class="guid"></generator>
    </id>
    <property name="OrderNo" column="order_no" length="8" not-null="true"></property>
    <property name="Status" column="status" not-null="true"></property>
    <many-to-one name="Orderer" class="Customer" column="customer_id" insert="true" not-found="exception" fetch="join"/>
  </class>
</hibernate-mapping>

Customer class:

namespace OODB.Domain
{
    public class Customer : ModelBase<Customer>
    {
        public virtual string FirstName
        {
            get;
            set;
        }

        public virtual string LastName
        {
            get;
            set;
        }

        public virtual string EMail
        {
            get;
            set;
        }

        public virtual string Telephone
        {
            get;
            set;
        }

        public virtual Address Address
        {
            get;
            set;
        }

...
}

Customer Order class:

public class CustomerOrder : ModelBase<CustomerOrder>
{
    public virtual string OrderNo
    {
        get;
        set;
    }

    public virtual Customer Orderer
    {
        get;
        set;
    }

    public virtual OrderStatus Status
    {
        get;
        set;
    }
...
}

Everything works great, if I remove the many-to-one stuff (Mappings are integrated as an embedded resource. I've checked this twice.). Otherwise I get the error 'An association from the table Orders refers to an unmapped class: OODB.Domain.Customer'. But the Customer object is mapped... What I am missing?

like image 319
Dennis Avatar asked Feb 22 '23 03:02

Dennis


1 Answers

My guess for your example: The "class" specification in the many-to-one element must have the same level of detail as every other class specification. Particularly, you must include the assembly.

<many-to-one name="Orderer" class="OODB.Domain.Customer, OODB.Domain" column="customer_id" insert="true" not-found="exception" fetch="join"/>
like image 198
Andrew Shepherd Avatar answered May 01 '23 07:05

Andrew Shepherd