title: Spring JPA CriteriaQuery child entity columns
body: <p>I am trying to make some dynamic mechanism to fetch data from db using criteria query based on given class, specification, select columns, aggregated columns and group by columns.</p>
  
  <p>Here's the code which is working fine:</p>
  
  <pre><code>    public &lt;T&gt; List&lt;T&gt; findDataByConfiguration(Specification&lt;T&gt; specification, 
          Class clazz, List&lt;String&gt; selectColumns, 
          List&lt;String&gt; aggregationColumns, List&lt;String&gt; groupByColumns) {
          CriteriaBuilder criteriaBuilder = this.entityManager.getCriteriaBuilder();
          CriteriaQuery&lt;Tuple&gt; query = criteriaBuilder.createTupleQuery();
          Root&lt;T&gt; root = query.from(clazz);
  
          List&lt;Selection&lt;?&gt;&gt; multiSelectColumns = new ArrayList&lt;&gt;();
          for (String s : selectColumns) {
              multiSelectColumns.add(root.get(s).alias(s));
          }
  
          for (String s : aggregationColumns) {
              multiSelectColumns.add(criteriaBuilder.sum(root.get(s)).alias(s));
          }
  
          List&lt;Expression&lt;?&gt;&gt; groupByColumnsList = new ArrayList&lt;&gt;();
          for (String s : groupByColumns) {
              groupByColumnsList.add(root.get(s));
          }
  
          query.groupBy(groupByColumnsList);
          query.multiselect(multiSelectColumns);
          query.where(specification.toPredicate(root, query, criteriaBuilder));
  
          List&lt;Tuple&gt; resultList = this.entityManager.createQuery(query).getResultList();
  
          // resultList processing
      }
  </code></pre>
  
  <p>This code is working fine when when I want to fetch data of flat entity class.
  But when I am trying to add child entiti'es field in select/aggregate/group by then it's throwing an error:</p>
  
  <p><strong>java.lang.IllegalArgumentException: Unable to locate Attribute  with the the given name [child.id] on this ManagedType [com.sup.as.data.entity.co.Annual]</strong></p>
  
  <pre><code>// annotations
  public class Annual {
      private Long id;
      private String fp;
      private ID iDetails;
      // getter-setter
  }
  
  public class ID {
      private Long id;
      private BigDecimal amount;
      // getter-setter
  
      public String giveMeData() {
          if(id != null &amp;&amp; amount != null) {
              return "FILED";
          } else {
              return "NOT FILED";
          }
      }
  }
  </code></pre>
  
  <p>now suppose I want field <strong>Annual.id, Annual.fp, SUM(Annual.iDetails.amount), Annual.iDetails.giveMeData</strong></p>
  
  <p>So is it possible to add child entities columns in select/aggregate/group by ?
  If anyone have done this type of solution then please help me to resolve this.</p>