title: How to implement ORDER BY from a Spring Data JPA GROUP BY query
body: <p>Based on question <a href="https://stackoverflow.com/q/36328063/5230740">How to return a custom object from a Spring Data JPA GROUP BY query</a>, my custom query is working, as follows:</p>
  
  <pre><code>@Query("select new br.com.cwidevs.dto.Goleador(j.id, sum(pj.gols)) from PartidaJogador pj join pj.id.jogador j group by j.id")
  public List&lt;Goleador&gt; getGoleadores();
  </code></pre>
  
  <p>Here is the simple bean class:</p>
  
  <pre><code>public class Goleador {
  
      private Long jogador;
  
      private Long totalGols;    
  }
  </code></pre>
  
  <p>At this point, how to implement <code>ORDER BY</code>? Can I achieve thi with <a href="https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.query-methods.sorting" rel="nofollow noreferrer">Sort</a>? </p>