Hibernate Mapping : Repeated column in mapping for entity

感情迁移 提交于 2019-12-13 04:45:51

问题


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?


回答1:


 <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" />


来源:https://stackoverflow.com/questions/33143115/hibernate-mapping-repeated-column-in-mapping-for-entity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!