开发者

Association references unmapped class exception [closed]

开发者 https://www.devze.com 2022-12-18 18:29 出处:网络
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. 开发者_开发知识库

This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.

Closed 11 months ago.

Improve this question

I'm trying to map the Northwind Employee entity with NHibernate:

public class Employee
{
    public virtual int ObjectID { get; set; }
    public virtual string LastName { get; set; }
    public virtual string FirstName { get; set; }
    public virtual string Title { get; set; }
    public virtual string TitleOfCourtesy { get; set; }
    public virtual DateTime HireDate { get; set; }
    public virtual DateTime BirthDate { get; set; }
    public virtual string Address { get; set; }
    public virtual string City { get; set; }
    public virtual string Region { get; set; }
    public virtual string PostalCode { get; set; }
    public virtual string Country { get; set; }
    public virtual string HomePhone { get; set; }
    public virtual string Extension { get; set; }
    public virtual byte[] Photo { get; set; }
    public virtual string Notes { get; set; }
    public virtual string PhotoPath { get; set; }

    public virtual ISet<Employee> Subordinates { get; set; }
    public virtual Employee ReportsTo { get; set; }
}

mapping:

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
auto-import="true" namespace="NHibernateTests.Data" assembly="NHibernateTests">
  <class name="Employee" lazy="false" entity-name="Employees">
    <id name="ObjectID" access="property" column="EmployeeID" >
      <generator class="native" />
    </id>
    <property name="LastName" access="property" column="LastName"/>
    <property name="FirstName" access="property" column="FirstName"/>
    <property name="Title" access="property" column="Title"/>
    <property name="TitleOfCourtesy" access="property" column="TitleOfCourtesy"/>
    <property name="BirthDate" access="property" column="BirthDate"/>
    <property name="HireDate" access="property" column="HireDate"/>
    <property name="Address" access="property" column="Address"/>
    <property name="City" access="property" column="City"/>
    <property name="Region" access="property" column="Region"/>
    <property name="PostalCode" access="property" column="PostalCode"/>
    <property name="Country" access="property" column="Country"/>
    <property name="HomePhone" access="property" column="HomePhone"/>
    <property name="Extension" access="property" column="Extension"/>
    <property name="Photo" access="property" column="Photo"/>
    <property name="Notes" access="property" column="Country"/>
    <property name="PhotoPath" access="property" column="PhotoPath"/>

    <set name="Subordinates" table="Employees" access="property" lazy="false" inverse="true">
      <key column="ReportsTo"/>
      <one-to-many class="Employee" />
    </set>

    <many-to-one name="ReportsTo" column="ReportsTo" access="property" not-null="false"/>
  </class>
</hibernate-mapping>

I keep getting "Association references unmapped class: NHibernateTests.Data.Employee" MappingException. It works fine with self-association parts (Subordinates and ReportsTo) commented out.

What's wrong with my mapping?


Sometimes, the above error occurs when we ddo not set properties for the particular HBM file. So, go to your hbm file properties and select the

BuildAction = EmbeddedResource

I have tested this scenario, wpf with Nhibernate environment.


Stupid error: used entity-name instead of table attribute.


In my most recent encounter with this, I had everything correct, except the HBM file was only 'EntityClass.xml' instead of 'EntityClass.hbm.xml'. Once I renamed the file, it worked out. I've been tripped on this previously from either different namespaces, or missing the 'Embedded Resource' on the HBM file.


I was getting this same error which resulted in a great deal of head scratching. So I just want to add my solution in case someone else has the same issue...

The entity I was referencing in the relationship was abstract, the result of a silly copy/paste typo. Once I took abstract out it executed just fine.

0

精彩评论

暂无评论...
验证码 换一张
取 消