title: Join by a single column instead of a composite primary key
body: <p>I have single JPA entity and I would to add self join on this table. Table looks like e.g.</p>
  
  <pre><code>@Entity
  @Table(name = "TABLE_A")
  @IdClass(TableAPk.class)
  public class TableA implements Serializable {
  
      private static final long serialVersionUID = 1L;
  
  
      @Id
      @Column(name = "COLUMN_1", nullable = false, length = 64)
      private String            column_1;
  
      @Id
      @Column(name = "COLUMN_2", nullable = false, precision = 10, scale = 2)
      private BigDecimal        column_2;
  
  
      @ManyToOne
      @JoinColumn(name = "COLUMN_1", insertable = false, updatable = false)
      //@ManyToOne(optional = true, fetch = FetchType.LAZY)
      //@JoinTable(name = "KEY_MAPPING", 
      //        joinColumns = { @JoinColumn(name = "J_COLUMN_1", referencedColumnName = "COLUMN_1", insertable = false, updatable = false) } )
      private TableA tableA;
  
      @OneToMany(mappedBy="tableA", fetch = FetchType.LAZY)
      private Set&lt;TableA&gt; tableASet;
  </code></pre>
  
  <p>And IdClass looks like:</p>
  
  <pre><code>public class TableAPk implements Serializable {
      // default serial version id, required for serializable classes.
      /** The Constant serialVersionUID. */
      private static final long serialVersionUID = 1L;
  
      private String            column_1;
  
      private BigDecimal        column_2;
  </code></pre>
  
  <p>As per my business logic I need to add self join only on single column</p>
  
  <pre><code>final Join&lt;TableA, TableA&gt; joinASelf = joinX.join("tableA", JoinType.INNER);
  </code></pre>
  
  <p>But table has composite primary key, so more than one fields are annotated with @Id. And I get exception like:</p>
  
  <p>Caused by: org.hibernate.AnnotationException: A Foreign key refering com.data.TableA from com.data.TableA has the wrong number of column. should be 2.</p>
  
  <p>How do i add self join only on single column here? I am new to JPA, so please let me know if I missed anything.</p>
  
  <p>Update 21 Feb 2015:
  I added annotation @AssociationOverride to override associations:</p>
  
  <pre><code>@ManyToOne
  @AssociationOverride(name="tableA", 
          joinColumns=@JoinColumn(name="COLUMN_1"))
  private TableA tableA;
  </code></pre>
  
  <p>Generated column name is shown as "TABLE_A_COLUMN_2". I am not able to find out why. Any clue?</p>