嗨,我正在尝试映射这个 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>