title: jpa criteria - expression based on db field name
body: <p>I have an entity called User, which has the following relationship to an entity called Company:</p>
  
  <pre><code>@Entity
  public class User {
  ...
  @ManyToOne
  @JoinColumn(name="COMPANY_ID",referencedColumnName="ID")
  private Company company = null;
  ...
  }
  </code></pre>
  
  <p>And on my database, I have a User table with a "COMPANY_ID" column. How can I create a JPA criteria query using this field?</p>
  
  <p>Using a criteria builder, I've tried the following expressions without success:</p>
  
  <pre><code>CriteriaBuilder cb = entityManager.getCriteriaBuilder();
  CriteriaQuery cq = cb.createQuery(User.class);
  Root mockEntityRoot = cq.from(User.class);
  
  //cq.where(cb.equal(mockEntityRoot.get("company"), 2));
  //cq.where(cb.equal(mockEntityRoot.get("COMPANY_ID"), 12));
  cq.where(cb.equal(mockEntityRoot.get("company.id"), 8));
  
  entityManager.createQuery(cq).getResultList();
  </code></pre>
  
  <p>But I got the following error: "The attribute [company.id] from the managed type User is not present."</p>
  
  <p>Thanks in advance.</p>