How to get java.util.Map from hibernate query?

后端 未结 1 867
难免孤独
难免孤独 2020-12-31 19:55

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 ther

相关标签:
1条回答
  • 2020-12-31 20:51

    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.

    0 讨论(0)
提交回复
热议问题