tags:

views:

100

answers:

1

I've been looking in the web for examples on the aggregates like count but it seems all of them are using the aggregate alone.

SELECT field, count(*) FROM table GROUP BY field

Should have something like:

field.value1, x1
field.value2, x2
....

I'm looking for a pure JPA answer for this one. If not I guess I can then do further queries just for the count part but that seems unefficient.

Any ideas?

+1  A: 

I'm not sure I understood the question correctly but doesn't the following JPQL query do what you want:

SELECT p.name, count(p) from Product p group by p.name
Pascal Thivent
Then how I retrieve the values from the result? It won't be a Product entity anymore?
javydreamercsw
See this [previous answer](http://stackoverflow.com/questions/2936685/jpql-what-kind-of-objects-contains-a-result-list-when-querying-multiple-columns/2936713#2936713).
Pascal Thivent