這是我的,我使用JPA打第二次,的Java,JPA轉換異常
我寫這篇PICE代碼:
String queryString = "SELECT e.uidprofile, e.profilecode, e.catUso, max(e.zonaClim), e.classePrev, e.beta1, e.beta2, e.beta3, e.beta4"
+ " FROM "
+ entityClass.getSimpleName()
+ " e "
+ " WHERE e.catUso like :code "
+ " group by e.uidprofile, e.profilecode, e.catUso, e.classePrev, e.beta1, e.beta2, e.beta3, e.beta4"
+ " order by e.uidprofile";
Query query = entityManager.createQuery(queryString);
query.setParameter("code", "C" + "%");
List<SamTbProfileMapping> resultList = query.getResultList();
ClassLoader c1 = this.getClass().getClassLoader();
ClassLoader c2 = resultList.getClass().getClassLoader();
if(resultList.size()>0){
System.out.println(resultList.get(0).getCatUso());
}
調試它:
- 擁有所有
SamTbProfileMapping
的字段值正確 - 對象的計數是正確的
- 行
List<SamTbProfileMapping> resultList = query.getResultList();
我得到C2
到null
和System.out.println(resultList.get(0).getCatUso());
說resultList不能被強制轉換爲SamTbProfileMapping
什麼的System.out.println(resultList.get( 0).getClass()getSimpleName())。返回? –
演員例外.. –
Ljava.lang.Object;無法投射到實體.SamTbProfileMapping –