Currently having troubles getting results from a simple aggregate function with HQL. Here is my query :
Query q = entityManager.createQuery("SELECT t.id.seq, COUNT(*) AS nb FROM TPEntity t WHERE t.id.num=:num GROUP BY t.id.seq");
q.setParameter("num", num);
With debugger, the query seems to execute properly. However, I cannot find the proper way to extract the result. I do get tons of ClassCastException. My current code is not raising any exception, but does not work :
List<Object> list = (List<Object>) q.getResultList();
if(list.size() > 0){
for(Object o : list){
if(o instanceof List){
return true;
}
}
}
return false;
This always returns false, event if debugger show me that o is of type “AbstractList” with two elements in it. Of course returning true is not the final code, I’d like to test if the aggregate value is greater than 1. This is just intermediate code for testing.
Thanks in advance for a piece of code.
For completeness, as proposed by Mark W, here is the solution for the cast :