Playframework的版本是1.2.x,我想把query.ResultList转换成VO。
我创建了一个 Part 实体 bean,如下所示:
@Entity
@Table(name="evaluation_part")
public class Part extends Model {
public String name;
public String collegeName;
public int peopleNum;
}
数据:
id name collegeName peopleNum
1 Jsj1 JJJJ 32
2 Jsj2 JJJJ 23
3 Jsj3 JJJJ 32
4 Tjb1 TTTT 11
5 Tjb2 TTTT 14
6 Tjb3 TTTT 16
我的价值对象类:
public class PartVO {
public String collegeName;
public int peopleNum;
}
我想使用本机查询来获得结果:
String sql="select collegeName,SUM(peopleNum) as peopleNum from evaluation_part group by collegeName";
查询结果为:
collegeName peopleNum
TTTT 41
JJJJ 87
我试过了:</p>
String sql="select collegeName,SUM(peopleNum) as peopleNum from evaluation_part group by collegeName";
Query query =JPA.em().createNativeQuery(sql);
List<PartVO> partVOs = query.getResultList();
for(int i=0;i<partVOs.size();i++) {
System.out.println(partVOs.get(i).collegeName);
}
以下错误是我得到的
ClassCastException occured : [Ljava.lang.Object; cannot be cast to valueobject.PartVO