Querydsl transformer group for account

I'm stuck trying to get a query (QueryDSL) for a job that gives me a number of different categories. For example, what am I trying to achieve:

categoryA -> 10 entries categoryB -> 20 entries 

This is what I still have:

 query().from(application) .transform(groupBy(application.category).as(list(application))); 

However, this gives me a list of all entire entries for each category, I just want to get a count of this.

I tried messing around with count() but no luck.

Does anyone know how to do this?

+3
source share
2 answers

transformBy combined group is designed to build tree structures from flat result sets. What you need is easier to express as

 query.from(application) .groupBy(application.category) .list(application.category, application.category.count()) 
+7
source

Please note that with Querydsl 4.x, Timo Westcamper's accepted answer is no longer valid. Breaking changes in Querydsl 4.0 has eliminated the query.list () method .

The solution working with Querydsl 4.0+ will now be:

 query.from(application) .groupBy(application.category) .select(application.category, application.category.count()) .fetch(); 
+12
source

Source: https://habr.com/ru/post/1233613/


All Articles