title: Criteria API - joining two tables throws an exception
body: <p>I have a database which contains the AccountOwner table and the Account table. The Account table has a PK "account_number", and the AccountOwner table has the same attribute as a FK. I am trying to join the two tables on this attribute, here is my code:</p>
  
  <pre><code>      EntityManager em = emfactory.createEntityManager();          
  
        CriteriaBuilder cb = em.getCriteriaBuilder(); 
        CriteriaQuery&lt;Account&gt; cq = cb.createQuery(Account.class);
        Root&lt;AccountOwner&gt; aroot = cq.from(AccountOwner.class);
  
        Join&lt;AccountOwner,Account&gt; ajoin = aroot.join("account_number");
  
        cq.select(ajoin).where(cb.equal(aroot.get("ClientId"),k.getClientID()));
  </code></pre>
  
  <p>However, this throws the following exception:</p>
  
  <pre><code>Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException:The attribute [account_number] is not present in the managed type 
  [EntityTypeImpl@18830730:AccountOwner[ javaType: class banking.AccountOwner descriptor: RelationalDescriptor(banking.AccountOwner--&gt; [DatabaseTable(acccount_owner)]), mappings: 3]].
  at org.eclipse.persistence.internal.jpa.metamodel.ManagedTypeImpl.getAttribute(ManagedTypeImpl.java:148)
  </code></pre>
  
  <p>I know for a fact that the attribute called exactly this in both the tables, here are the relevant parts of the entity classes:</p>
  
  <pre><code>public class AccountOwner implements Serializable {
  //...
  
  @JoinColumn(name = "account_number", referencedColumnName = "account_number")
  @ManyToOne(optional = false)
  private Account accountNumber;
  //...
  
  }
  
  
  
  
  public class Account implements Serializable {
  //....
  
  @Column(name = "account_number")
  private Integer accountNumber;
  @Basic(optional = false)
  
  //....
  }
  </code></pre>
  
  <p>What am I doing wrong?</p>