@ManyToMany具有共享字段的复合键的两个实体

时间:2010-08-28 04:15:36

标签: hibernate orm jpa

两个实体:

public class Employee {
  Company company;
  Long employeeId;
}
public class Project {
  Company company;
  Long projectId;
  Collection<Employee> employees;
}

三张桌子:

  • 主键为{companyId,projectId}
  • 的项目
  • 主键为{companyId,employeeId}
  • 的员工
  • Project_Employee,其主键为{companyId,projectId,employeeId}

xml中的映射:

<entity class="domain.Project">

 <attributes>
  <many-to-many name="employees" >
   <join-table name="PROJECT_EMPLOYEE">
    <join-column name="companyId" referenced-column-name="companyId"/>
    <join-column name="employeeId" referenced-column-name="employeeId" />
    <inverse-join-column name="companyId" referenced-column-name="companyId" />
    <inverse-join-column name="projectId" referenced-column-name="projectId" />
   </join-table>
  </many-to-many>  
 </attributes>

</entity>

我收到错误抱怨公司多次出现: 收集映射中的重复列:Project.employees列:companyId

Hibernate用

映射它
<formula>companyId</formula>

JPA 1.0是否支持此功能?

0 个答案:

没有答案