本文介绍了Hibernate映射:实体映射中的重复列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个类Employee和Application。
员工有一个employeeId(PK)。应用程序有两个字段employeeId(fk)managerId(fk)。 employeeId和managerId都应该引用Employee类的employeeId。所以我在各自的hbm.xml文件中有以下映射:

Employee.hbm.xml

 < hibernate-mapping package =com.quinnox.resignation2.0.model> 
< class name =Employeetable =Employee>
< id name =employeeIdtype =int>
< generator class =native>< / generator>
< / id>
< / class>
< hibernate-mapping>

Application.hbm.xml

 < hibernate-mapping package =com.quinnox.resignation2.0.model> 
< class name =Applicationtable =Application>
< id name =applicationIdtype =int>
< generator class =native>< / generator>
< / id>
column =employeeId/>
< / class>< / hibernate-mapping>

我也创建了合适的POJO。当我尝试运行应用程序时,出现以下错误:

  org.hibernate.MappingException:实体映射中的重复列:com .quinnox.resignation2.0.model.Application列:employeeId(应该被映射为insert =falseupdate =false)

我无法设置insert =false或update =false,并且这两个外键都应映射到Employee表的employeeId。

解决方案
 <多对一名称=managerId class =Employee
column =employeeId/>

可能应该引用 managerId employeeId

 <多对一名称=managerId class =Employee
column =managerId/>


I have two classes Employee and Application.Employee has an employeeId(PK). Application has two fields employeeId(fk) managerId(fk). Both employeeId and managerId should refer to employeeId of class Employee. So i have following mappings in the respective hbm.xml files:

Employee.hbm.xml

   <hibernate-mapping package="com.quinnox.resignation2.0.model">
        <class name="Employee" table="Employee">
            <id name="employeeId" type="int">
                <generator class="native"></generator>
            </id>
</class>
<hibernate-mapping>

Application.hbm.xml

<hibernate-mapping package="com.quinnox.resignation2.0.model">
    <class name="Application" table="Application">
        <id name="applicationId" type="int">
            <generator class="native"></generator>
        </id>
        <many-to-one name="empId" class="Employee" column="employeeId" />
        <many-to-one name="managerId" class="Employee"
            column="employeeId" />
</class></hibernate-mapping>

I have also created appropriate POJOs. When I try to run the application i get the following error

org.hibernate.MappingException: Repeated column in mapping for entity: com.quinnox.resignation2.0.model.Application column: employeeId (should be mapped with insert="false" update="false")

I cannot set insert="false" or update="false" and both the foreign keys should map to employeeId of Employee table. What do I do?

解决方案
 <many-to-one name="managerId" class="Employee"
        column="employeeId" />

May be it should reference managerId column rather than employeeId

 <many-to-one name="managerId" class="Employee"
        column="managerId" />

这篇关于Hibernate映射:实体映射中的重复列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 08:34