我的数据库中有一个名为employee_project
的表,该表已使用以下列EMPLOYEE_NUMBER,PROJECT_CODE,START_DATE,END_DATE,PROJECT_ROLE
创建。我使用过的employee and project
之间有一对多的关系
private Set<EmployeeProject> employeeProjects = new HashSet<EmployeeProject>();
,在employee_project表中扩展了一些列employeeProject_PROJECT_CODE,employeeProject_EMPLOYEE_NUMBER
。有没有办法限制hibernate不扩展列导致表已经制作?在项目表中还有一个名为EMPLOYEE_NUMBER.PROJECT_CODE
的复合id。还有一个问题是为什么hibernate为collection元素创建额外的表或扩展现有表中的列?
Employee.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>
project.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