开发者

@ManyToMany of two entities with composite keys that share a field

Two entities:

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

Three tables:

  • Project whose primary key is {companyId,projectId}
  • Employee whose primary key is {companyId,employeeId}
  • Project_Employee whose primary key is {companyId,projectId,employeeId}

Mapping in 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>

I received a error complaining companyId appearing multiple times: Repeated column in mapping for collection: Project.employees column: companyId

Hibernate maps this with

<formula>companyId</formula>

Does JPA 1.0 support this functionality?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜