我employee_project
在我的数据库上调用了表,该表已经由以下列创建EMPLOYEE_NUMBER,PROJECT_CODE,START_DATE,END_DATE,PROJECT_ROLE
。employee and project
我使用的 for之间存在一对多关系
private Set<EmployeeProject> employeeProjects = new HashSet<EmployeeProject>();
由于这个集合,在 Employee pojo 类中,一些列在我的employee_project 表中扩展,它们是 employeeProject_PROJECT_CODE,employeeProject_EMPLOYEE_NUMBER
. 有什么方法可以限制休眠不扩展列,因为表已经制作好了?项目表中的另一件事是复合 id 命名EMPLOYEE_NUMBER.PROJECT_CODE
。还有一个问题是为什么 hibernate 为集合元素创建额外的表或扩展现有表中的列?
员工.hbm.xml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.nousinfo.tutorial.model">
<class name="Employee" table="employee">
<meta attribute="class-description">
This class contains the employee detail
</meta>
<id name="employeeNumber" type="int" column="EMPLOYEE_NUMBER">
</id>
<property name="firstName" type="string" column="FIRST_NAME"></property>
<property name="lastName" type="string" column="LAST_NAME"></property>
<property name="title" type="string" column="TITLE"></property>
<property name="departmentId" type="string" column="DEPARTMENT_ID"></property>
<set name="employeeProjects" cascade="delete"
inverse="false">
<key column="EMPLOYEE_NUMBER" />
<one-to-many class="com.nousinfo.tutorial.model.EmployeeProject" />
</set>
<property name="address1" type="string" column="ADDRESS_1"></property>
</class>
</hibernate-mapping>
项目.hbm.xml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.nousinfo.tutorial.model">
<class name="EmployeeProject" table="employee_project">
<meta attribute="class-description">
This class contains the employee detail
</meta>
<composite-id>
<key-property name="employeeNumber" type="int"
column="EMPLOYEE_NUMBER"></key-property>
<key-property name="projectCode" type="string" column="PROJECT_CODE"></key-property>
</composite-id>
<property name="startDate" type="date" column="START_DATE"></property>
<property name="endDate" type="date" column="END_DATE"></property>
<property name="role" type="string" column="PROJECT_ROLE"></property>
<many-to-one name="employee" column="EMPLOYEE_NUMBER" class="com.nousinfo.tutorial.model.Employee" not-null="true" insert="false" update="false" ></many-to-one>
</class>
</hibernate-mapping