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