tags:

views:

13

answers:

0

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?