title: How to select just the foreign key value using Criteria Query?
body: <p>Suppose I have two entities as:</p>
  
  <pre><code>@Entity
  public class A {
  
      @Id
      private int id;
  
      @ManyToOne
      private B b; 
  
      //more attributes
  }
  
  @Entity
  public class B {
  
      @Id
      private int id;
  }
  </code></pre>
  
  <p>So, the table for A is having a column as <code>b_id</code> as the foreign key. </p>
  
  <p>Now, I want to select just the <code>b_id</code> based on some criteria on other fields. How can I do this using criteria query?</p>
  
  <p>I tried doing following which throws IllegalArgumentException saying <code>"Unable to locate Attribute with the given name [b_id] on this ManagedType [A]"</code></p>
  
  <pre><code>    CriteriaQuery&lt;Integer&gt; criteriaQuery = criteriaBuilder.createQuery(Integer.class);
      Root&lt;A&gt; root = criteriaQuery.from(A.class);
      Path&lt;Integer&gt; bId = root.get("b_id");
      //building the criteria
      criteriaQuery.select(bId);
  </code></pre>