我有两个映射文件,分别对应于order和customer对象。
客户映射:
<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>订单映射:
<?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类:
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;
}
...
}客户订单类:
public class CustomerOrder : ModelBase<CustomerOrder>
{
public virtual string OrderNo
{
get;
set;
}
public virtual Customer Orderer
{
get;
set;
}
public virtual OrderStatus Status
{
get;
set;
}
...
}如果我去掉多对一的东西,一切都很好用(Mappings被集成为嵌入式资源。我已经检查过两次了。)否则,我会得到一个错误:“来自表Orders的关联引用了一个未映射的类:OODB.Domain.Customer”。但是客户对象被映射了.我错过了什么?
发布于 2011-12-14 17:34:32
我混淆了class元素上的table和entity-name属性。:\
发布于 2011-12-13 07:36:01
我对您的示例的猜测是:many-to-one元素中的“类”规范必须与其他class规范具有相同的详细程度。特别是,您必须包括程序集。
<many-to-one name="Orderer" class="OODB.Domain.Customer, OODB.Domain" column="customer_id" insert="true" not-found="exception" fetch="join"/>发布于 2013-12-07 05:31:33
此异常的一个可能原因是.html文件不是“嵌入式资源”。如果映射文件(hbm)不在正确的目录中,则此异常。如果您查看输出窗口,您将看到类似以下内容:
NHibernate.Cfg.Configuration: ERROR lambda_method - An association from the table
SubsequentReportDetail refers to an unmapped class: NS.Project.Data.Domain.Class
NHibernate.MappingException: An association from the table X refers to an
unmapped class: NS.Project.Data.Domain.Classhttps://stackoverflow.com/questions/8482372
复制相似问题