我有两个类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="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>
我还创建了适当的POJO。当我尝试运行应用程序时,我收到以下错误
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")
我无法设置insert =&#34; false&#34;或者更新=&#34; false&#34;并且两个外键都应该映射到Employee表的employeeId。我该怎么办?
答案 0 :(得分:0)
<many-to-one name="managerId" class="Employee"
column="employeeId" />
可能应该引用managerId
列而不是employeeId
<many-to-one name="managerId" class="Employee"
column="managerId" />