title: Limitation of JPA 1.0 using @IdClass with *nested* composite primary keys?
body: <p>Given the following example (departments - projects):</p>
  
  <p>A department has the following properties (composite primary key):</p>
  
  <pre><code>@Entity
  @IdClass(DeptId.class)
  public class Department
  {
      @Id
      @Column(name="number")
      private Integer number;
  
      @Id
      @Column(name="country")
      private String country;
  
      @Column(name="name")
      private String name;
  
      @OneToMany(mappedBy="dept")
      private Collection&lt;Project&gt; projects;
  
      ...
  }
  </code></pre>
  
  <p>Here the PK class:</p>
  
  <pre><code>public class DeptId implements Serializable
  {
      private Integer number;
      private String country;
  
      ...
  }
  </code></pre>
  
  <p>The relationship between projects and departments is many-to-one, that is a deptartment can have many projects. The Project class is itself using a composite key referencing Department's composite key. Important note: it's only about the implementation with @IdClass not @EmbeddedId.</p>
  
  <p>Then the (problematic) JPA 1.0 @IdClass implementation would have to look something like that (redundant deptNum and deptCtry properties): -> it's just a unique name within a department</p>
  
  <pre><code>@Entity 
  @IdClass(ProjectId.class)
  public class Project
  {
      @Id
      @Column(name="dept_number")
      private Integer deptNumber;
  
      @Id
      @Column(name="dept_country")
      private String deptCountry;
  
      @Id
      @Column(name="name")
      private String name;
  
      @ManyToOne 
      @JoinColumns({
         @JoinColumn(name="dept_number", referencedColumnName="number"),
         @JoinColumn(name="dept_country", referencedColumnName="country")
      })    
      private Department dept;
  
      ...
  }
  </code></pre>
  
  <p>The ProjectId is:</p>
  
  <pre><code>public class ProjectId implements Serializable
  {
      private String name;
      private DeptId dept;
  
      ...
  }
  </code></pre>
  
  <p>The problem with this is that neither Hibernate nor EclipseLink know how to map the two redundant properties deptNum and deptCtry in Project to the dept property in DeptId (or the properies within it). -> MappingException etc.</p>
  
  <p>My question is:</p>
  
  <p>Is this a limitation of JPA 1.0, that tables with composite keys referencing other composite keys with @IdClass implementations <em>generally WON'T work</em>, because the JPA implementation simply can't know how to map these fields?</p>
  
  <p>As a workaround, you'd have to use @EmbeddedId for these classes or use JPA 2.0 syntax to annotate the @XToX associations with @Id. I just want to make sure my view on this is right.</p>
  
  <p>Thanks</p>