returning Map in HQL
I was going through hibenate documentation and found that it is possible to return map from HQL by using code:
select new map( max(bodyWeight) as max, min(bodyWeight) as min, count(*) as n )
from Cat cat
But I am not able to understand when I execute query how to get map and use alias for retrieving each column.
开发者_JS百科The method for getting results are either query.list of query.iterate. Which function to call if I need to get result as map and how to retrieve each column from map using alias.
thanks
In situations like this, I use the debugger to see what is actually returned. In this case, the query does not return rows, it returns only three values: max
, min
, and n
. So you can get the result and do something like
resultMap.get("max");
because in the hql you told hibernate to label the result for max as 'max'.
精彩评论