title: Hibernate looking for parent field name on join to child table
body: <p>I've got three tables in my database: </p>
  
  <pre class="lang-sql prettyprint-override"><code>create table A (
    a_id int primary key
  );
  
  create table B (
    b_id int primary key references A(a_id)
  );
  
  create table C (
    c_id int primary key,
    b_id int references B(b_id)
  );
  </code></pre>
  
  <p>and I modelled them using following JPA-annotated classes:</p>
  
  <pre class="lang-java prettyprint-override"><code>@Entity(name = "A")
  @Table(name = "A")
  public class A {
      @SuppressWarnings("unused")
      @Id
      @Column(name = "A_ID")
      private int id;
  }
  
  @Entity(name = "B")
  @Table(name = "B")
  @PrimaryKeyJoinColumns({@PrimaryKeyJoinColumn(name = "B_ID", referencedColumnName = "A_ID")})
  public class B extends A {
  }
  
  @Entity(name = "C")
  @Table(name = "C")
  public class C {
      @SuppressWarnings("unused")
      @Id
      @Column(name = "C_ID")
      private int id;
  
      @SuppressWarnings("unused")
      @OneToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH, CascadeType.DETACH})
      @JoinColumns(value = {
          @JoinColumn(name = "B_ID", referencedColumnName = "B_ID", insertable = false, updatable = false)})
      private B b;
  }
  </code></pre>
  
  <p>When I try to use these classes with Hibernate entity manager, it complains with the following error:</p>
  
  <p><code>Unable to find column with logical name: B_ID in org.hibernate.mapping.Table(A) and its related supertables and secondary tables</code></p>
  
  <p>Changing <code>referencedColumnName</code> ont the C to B join to <code>A_ID</code> seems to make it happy. Why is that? Can't I model the relationships as they are in the database?</p>