简体   繁体   中英

How to use GroupBy with Spring JPA Specifications (JPA Specification Executor)

I'm looking for a way to use multiple (or at least one) group by in my JPA Specifications. I've found that i can put, for example:

cq.groupBy(root.get("id"));

in my specification but the problem is that JpaSpecificationExecutor doesn't have proper interface to support this aggregation as there is no method that returns a Map nor there is a possibility to have my own DTO as a return type (as far as i know).

The Specification interface is only intended for specifying WHERE-clauses. If you wan't to specify GROUP BY or anything else affecting the columns selected as opposed to the rows selected you should write a custom method to meet your needs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM