失败的hibernate映射:表X中的关联指的是未映射的类Y.

嗨,我正在尝试映射这个pojo Rent类来创建他的hibernate映射文件.

Rent.java(POJO):

  public class Rent implements Serializable {

     private static final long serialVersionUID = 1L;

       Employee employee;
       Client client;
       Car car;

    /* + getter and setter... */
  } 

我的目的是创建一个web应用程序,用户可以设置哪个员工租了一辆车到客户端.所以这是我试过的实现

Rent.hbm.xml:

<hibernate-mapping>
  <class name="com.google.musicstore.domain.Rent" table="RENT">
    <id name="id" column="RENT_ID">
       <generator class="native"/>
    </id>
    <one-to-one name="car"  class="com.project.domain.Car"
       cascade="save-update">
    </one-to-one>
    <one-to-one name="client"  class="com.project.domain.Client"
       cascade="save-update">
    </one-to-one>
    <many-to-one name="employee"  class="com.project.domain.Employee"
       cascade="save-update">
    </many-to-one>
  </class>
</hibernate-mapping>

但它给了我这个错误:

   [java] Initial SessionFactory creation failed.org.hibernate.MappingException: An association from the table RENT refers to an unmapped class: com.project.domain.Employee

我究竟做错了什么?感谢您的帮助.

我还映射了hibernate.cfg.xml中的所有实体:

    <mapping resource="com/project/carRentalAgency/domain/Employee.hbm.xml"/>
    <mapping resource="com/project/carRentalAgency/domain/Client.hbm.xml"/>
    <mapping resource="com/project/carRentalAgency/domain/Car.hbm.xml"/>
    <mapping resource="com/project/carRentalAgency/domain/Rent.hbm.xml"/>

[编辑]作为请求,我添加了文件
Employee.hbm.xml

   <hibernate-mapping>
       <class name="com.project.carRentalAgency.domain.Employee" table="EMPLOYEE">
            <id name="id" type="long" access="field">
                <column name="ID" />
                <generator class="increment" />
            </id>
            <property name="name" type="java.lang.String" access="field">
                <column name="EMPLOYEE_NAME" />
           </property>
           <property name="surname" type="java.lang.String">
                <column name="EMPLOYEE_SURNAME" />
           </property>
           <property name="username" type="java.lang.String">
                <column name="EMPLOYEE_USERNAME" />
           </property>
           <property name="password" type="java.lang.String">
                <column name="EMPLOYEE_PASSWORD" />
           </property>

      </class>
   </hibernate-mapping>
最佳答案
我能想到两种可能性:

(1)您在Employee.hbm.xml中的类名不是完全限定的类名

(2)您没有在hibernate.cfg.xml中声明所有映射资源.

您可能需要提供更多信息,例如Employee.hbm.xml和hibernate.cfg.xml以及Rent.hbm.xml以供我们检查.

转载注明原文:失败的hibernate映射:表X中的关联指的是未映射的类Y. - 代码日志