如何从hibernate查询中获取java.util.Map? [英] How to get java.util.Map from hibernate query?
本文介绍了如何从hibernate查询中获取java.util.Map?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道从hibernate查询获取地图数组的最佳方式是什么。谷歌说,要迭代query.list(),并创建/将对象放入空映射数组中。
我想会有一些优雅而有效的方法来做到这一点。可能有人给我想法吗?
您可以使用as为所选表达式分配别名:
从cat cat
$ p选择max(bodyWeight)作为min,min(bodyWeight)作为min,count(*)作为n
$ p>
当与选择新地图一起使用时,这是最有用的:
选择新的地图(max(bodyWeight)as max,min(bodyWeight)min,count(*)as n)
from cat cat
该查询返回一个从别名到选定值的映射。
I am wondering what is the best way to get map array from hibernate query. Google says to iterate query.list(), and create/put objects into empty map array.
I guess there would be some elegant and efficient way to do this. Could somebody give me idea?解决方案See Hibernate Documentation - 15.6. The select clause:
You can assign aliases to selected expressions using as:
select max(bodyWeight) as max, min(bodyWeight) as min, count(*) as n from Cat cat
This is most useful when used together with select new map:
select new map( max(bodyWeight) as max, min(bodyWeight) as min, count(*) as n ) from Cat cat
This query returns a Map from aliases to selected values.
这篇关于如何从hibernate查询中获取java.util.Map?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文