2

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!

Xstian
  • 8,184
  • 10
  • 42
  • 72
topcan5
  • 1,511
  • 8
  • 30
  • 54
  • Spring Data Jpa does support group by, see http://stackoverflow.com/a/36329166/3095671 – mpr Jan 24 '17 at 12:18

2 Answers2

2

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.

mavarazy
  • 7,562
  • 1
  • 34
  • 60
1

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

  • 1
    Welcome to StackOverflow! Please see [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`. – Kateract Dec 13 '16 at 17:11