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?
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"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With