开发者

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'.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜