问题
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