title: JPA & Criteria API - Select only specific columns
body: <p>I would like to select only specific columns (ex. <code>SELECT a FROM b</code>). I have a generic DAO and what I came up with is:</p>
  
  <pre><code>public List&lt;T&gt; getAll(boolean idAndVersionOnly) {
      CriteriaBuilder builder = manager.getCriteriaBuilder();
      CriteriaQuery&lt;T&gt; criteria = builder.createQuery(entityClazz);
      Root&lt;T&gt; root = criteria.from(entityClazz);
      if (idAndVersionOnly) {
          criteria.select(root.get("ID").get("VERSION")); // HERE IS ERROR
      } else {
          criteria.select(root);
      }
      return manager.createQuery(criteria).getResultList();
  }
  </code></pre>
  
  <p>And the error is:
  <code>The method select(Selection&lt;? extends T&gt;) in the type CriteriaQuery&lt;T&gt; is not applicable for the arguments (Path&lt;Object&gt;)</code>. How should I change that? I want to get a type <code>T</code> object that has only <code>ID</code> and <code>VERSION</code> fields, and all others are <code>null</code>.</p>
  
  <p>Type <code>T</code> extends <code>AbstractEntity</code> which has those 2 fields.</p>
  
  <p><code>entityClazz</code> is <code>T.class</code>.</p>