java Spring Data Jpa 不支持 Groupby

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34280754/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 22:40:33  来源:igfitidea点击:

Spring Data Jpa not support Groupby

javaspringjpaspring-data-jpa

提问by topcan5

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?

我需要快速搜索对象列表。Spring Data Jpa 不支持 GroupBy 是真的吗?如果是这样,没有写作的解决方法是@Query什么?

Thanks!

谢谢!

采纳答案by mavarazy

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

如果您出于某种原因不喜欢 @Query,那么您至少还有 2 个选择:

  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
  1. CriteriaAPI 与 spring-data-jpa 规范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.

它们都支持分组操作。

回答by radekolejarski

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

是的 CriteriaAPI 支持 groupBy 但不支持 spring 规范!getQuery 中的类 SimpleJpaRepository 通过 query.select(root) 替换查询选择/多选;:(