it is my second time that i play with jpa,
i wrote this pice of code:
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());
}
Debugging it:
resultListhas all the fields ofSamTbProfileMappingwith the right values- the count of the objects is right
- after the line
List<SamTbProfileMapping> resultList = query.getResultList();
i getC2tonullandSystem.out.println(resultList.get(0).getCatUso());
says that resultList can not be Casted ToSamTbProfileMapping
You are retrieving a list of arrays with your query. Not a list of objects.
"Select a, b, c, d, from something"– returnsList<Object[]>Then access separate members in the same order as in query.
For example:
To select an object list you can use:
"select a from MyClass a where ..."Then