Spring Data Jpa not support Groupby

17,921

Solution 1

If you don't like @Query for some reason, you, at least, have 2 more options:

  1. CriteriaAPI with spring-data-jpa Specifications http://docs.spring.io/spring-data/jpa/docs/1.9.1.RELEASE/reference/html/#specifications
  2. QueryDSL http://www.querydsl.com/static/querydsl/4.0.7/reference/html_single/#d0e372

They both support grouping operations.

Solution 2

Yes CriteriaAPI supports groupBy but spring Specification not! class SimpleJpaRepository in getQuery replace query select/multiselect by query.select(root); :(

Share:
17,921

Related videos on Youtube

topcan5
Author by

topcan5

Updated on September 15, 2022

Comments

  • topcan5
    topcan5 over 1 year

    I need a quick search for a list of objects. Is that true that Spring Data Jpa doesn't support GroupBy? If so, what's the work around without writing @Query?

    Thanks!

  • Kateract
    Kateract over 7 years
    Welcome to StackOverflow! Please see How to Answer for tips on giving good answer to questions on this site. In general, it's best to focus on new questions that don't have accepted answers. Also, check out the formatting options to correctly show code blocks.