4

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

Rent.java (POJO):

  public class Rent implements Serializable {

     private static final long serialVersionUID = 1L;

       Employee employee;
       Client client;
       Car car;

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

我的目的是创建网络应用程序,用户可以在其中设置哪个员工向客户租车。所以这是我尝试过的实现

租.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>

4

2 回答 2

11

我发现通常会发生此错误,因为休眠文件 classname.hbm.xml 属性的构建操作未设置为嵌入式资源。

于 2014-02-04T20:00:08.310 回答
8

我能想到的有两种可能:

(1) 你的类名不是Employee.hbm.xml全限定类名

(2) 您没有在hibernate.cfg.xml.

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

于 2013-10-28T11:57:47.097 回答