Group By « Map « JPA Q&A

1. Hibernate Criteria API: count and group by with result in Map

The Car entity is mapped to a database table with 2 columns: ID and Color. CarDao has the following method:

Map<Color, Integer> countByColor();
If we have 3 red cars and 2 blue cars in ...

2. Group by discriminator value in table per class hierarchy mapping

Is it possible to write a HQL query that groups results by the discriminator value of a table per class hierarchy mapping? For instance

"select discriminator d, count(*) c from Foo group ...

3. Hibernate key mapping for GROUP BY

4. How to map or assign the result of a group by to a property?

Domain Object: class Project { private int numberOfWorkers; private String name; } class Worker { private Project project; } The usual mapping is done in hbm.xml's. I am running the following query: SELECT project, COUNT(worker) FROM Worker worker GROUP BY worker.project; I want to assign COUNT(worker) to Project.numberOfWorkers through mapping, the query itself or some other mechanism preferably not looping through ...

5. How to use GROUP BY in query against map collections ?

Newbie Joined: Thu Dec 09, 2004 9:03 am Posts: 2 Location: Glasgow, United Kingdom Hi, I'm trying to execute query that performs a count(*) on the elements of map attached to a parent object and I'm stuck with not knowing how to write the HQL. The objects involved look like: ContentDescriptor Quote: .id .url .project