JPA and aggregate functions. How do I retrieve the query result?
822327May 26 2011 — edited Jun 30 2011I read the documentation, there's JPQL Constructor Expressions:
for example:
SELECT new com.yourproject.ResultHolder(insp, COUNT(test.testId))
FROM Inspection insp LEFT JOIN insp.testList AS test GROUP BY insp.inspId
OR:
SELECT new list(insp, COUNT(test.testId))
FROM Inspection insp LEFT JOIN insp.testList AS test GROUP BY insp.inspId
Now how do we process the query result from here? (I couldn't find anywhere in the documentation)
Is it like the following (the select statement above, is it supposed to be lowercase "list" as a variable or uppercase "List" as the type)?
List list = (List)selectQuery.getSingleResult();
Inspection insp = (Inspection)list.get(0);
int count = list.get(1);