Hibernate中HQL语句查询指定字段值报错:ClassCastException: [java.lang.Object; cannot be cast to bean.PersonStatic



Hibernate中HQL语句查询指定字段值报错:ClassCastException: [java.lang.Object; cannot be cast to bean.PersonStatic

在有一次通过如下HQL语句进行查找相应字段时:
String hql = "select sum(search),sum(geometry),sum(greedy),
sum(graph),sum(number),sum(simulate),sum(combine),sum(structure)
from PersonStatis ps where ps.ps_date>=? and ps.ps_date<?";
通过Query中的方法list()返回一个List对象。
但是当通过VO类PersonStatis提取数值的时候居然报错:
java.lang.ClassCastException:
[Ljava.lang.Object; cannot be cast to bean.PersonStatis居然不能转换。
通过多方验证,这个返回的List中并不是存放的是PersonStatis对象,而是存放的查询出来对应于字段顺序的一个数组对象。
于是我们需要通过Object[] obj = list.get(0);然后在根据相应的数组下标取得相应的值。