title: how to get tuple with average(xxx) by spring data jpa specification?
body: <p>I want to get the <code>List&lt;Map&lt;String,Object&gt;&gt;</code>returned by query like this:</p>
  
  <pre><code>[{production:{the object}, avgscore:123}, {production:{other object},avgscore:456}, ...]
  </code></pre>
  
  <p>I can get it by this :</p>
  
  <pre><code>public interface ProductionRepository extends PagingAndSortingRepository&lt;Production, Long&gt; {
      @Query("SELECT p as productions,avg(c.score) as avgscore FROM ......")
      List&lt;Map&lt;String,Object&gt;&gt; findSorted(......);
  }
  </code></pre>
  
  <p>but now I try to use Specification, and I done the specification:</p>
  
  <pre><code>Specification specification = new Specification() {
          @Override
          public Predicate toPredicate(Root root1, CriteriaQuery query, CriteriaBuilder cb) {
              .......
              .......
              if (date2 != null) {
                  Predicate endTimeP = cb.lessThanOrEqualTo(root.get(Production_.productDate), date2);
                  predicates.add(endTimeP);
              }
              query.groupBy(root.get(Production_.id)).orderBy(cb.desc(cb.avg(commentJoin.get(Comment_.score))));
              Predicate[] predicates1 = new Predicate[predicates.size()];
              predicates.toArray(predicates1);
              query.multiselect(root.alias("production"),
                      cb.avg(commentJoin.get(Comment_.score)).as(Double.class).alias("avgscore"));
              return cb.and(predicates1);
  }
  </code></pre>
  
  <p>and then I use this to findAll:</p>
  
  <pre><code>return specificationRepo.findAll(specification);
  </code></pre>
  
  <p>the repository is:</p>
  
  <pre><code>@Repository
  public interface SpecificationRepository extends PagingAndSortingRepository&lt;Production, Long&gt;,
          JpaSpecificationExecutor {
      List&lt;Map&lt;String,Object&gt;&gt; findAll(Specification specification);
  }
  </code></pre>
  
  <p>BUT, the findAll() only return <code>List&lt;Production&gt;</code> , no matter how I change the return type, it always return <code>List&lt;production&gt;</code> , not <code>List&lt;Map&lt;String,Object&gt;&gt;</code> I wanted.</p>
  
  <p>it it bind to the Production in <code>PagingAndSortingRepository&lt;Production, Long&gt;</code>. If I delete this and only have JpaSpecificationExecutor, spring will not seem it as a @Repository; The Production position must be a @Entity, I can not change it to a custom java thing having Production and avgscore.</p>
  
  <p>I have searched long time, but still didn't find how to solve.</p>