Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spring hibernate.createSQLQuery return as custom entity

I am doing Query query = hibernate.createSQLQuery("select abc,def from table");

Is it possible to auto "parse" the result to "POJO" list?

So that I can do this:

List<CustomPOJO> abc = query.list();    //CustomPOJO is pojo not entity , no @Entity tag 
like image 422
cometta Avatar asked Feb 02 '10 10:02

cometta


1 Answers

Try

hibernate.createSQLQuery("select abc,def from table").setResultTransformer(Transformers.aliasToBean(CustomPOJO.class));

like the reference manual suggests.

like image 107
Tadeusz Kopec for Ukraine Avatar answered Nov 15 '22 17:11

Tadeusz Kopec for Ukraine