title: jpa hibernate @OneToOne @JoinColumn referencedColumnName ignored
body: <p>I am experiencing an unexpected behavior while performing a jpql query on an entity having a one-to-one relationship with another. The key point is that the relationship is from the primary key of the root entity to a field of the destination entity which is not the ID.</p>
  
  <p>Here is the example:</p>
  
  <pre><code>// root entity
  @Entity
  @Table(name = "PERSON")
  
  public class Person {
  
      @Id
      @Column(name = "PERSON_ID")
      private long id;
  
      private String name;
  
      @OneToOne(optional = false)
      @JoinColumn(name = "PERSON_ID", referencedColumnName = "PERSON_ID", insertable = false, updatable = false, unique = true)
      private Address mainAddress;
      ...
  }
  // referenced entity
  @Entity
  @Table(name = "ADDRESS")
  public class Address {
  
      @Id
      @Column(name = "ADDRESS_ID")
      private long id;
  
      @Column(name = "PERSON_ID")
      private long personId;
      ...
  }
  </code></pre>
  
  <p>The following jpql query:</p>
  
  <pre><code>select p from Person p left join fetch p.mainAddress
  </code></pre>
  
  <p>Produces the following ORACLE SQL query:</p>
  
  <pre><code>SELECT ... FROM PERSON p LEFT OUTER JOIN ADDRESS a ON p.PERSON_ID = a.ADDRESS_ID
  </code></pre>
  
  <p>While I expected :</p>
  
  <pre><code>SELECT ... FROM PERSON p LEFT OUTER JOIN ADDRESS a ON p.PERSON_ID = a.PERSON_ID
  </code></pre>
  
  <p>Basically the attribute of the <strong>referencedColumnName = "PERSON_ID"</strong> attribute is ignored and the join is performed on the primary key.</p>
  
  <p>Somebody can please explain me why?</p>