春季hibernate.createSQLQuery返回为自定义实体 [英] spring hibernate.createSQLQuery return as custom entity
本文介绍了春季hibernate.createSQLQuery返回为自定义实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在做查询查询= hibernate.createSQLQuery(select abc,def from table);
是否可以将结果自动解析为POJO列表?
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
推荐答案
尝试
hibernate.createSQLQuery("select abc,def from table").setResultTransformer(Transformers.aliasToBean(CustomPOJO.class));
就像参考手册建议。
这篇关于春季hibernate.createSQLQuery返回为自定义实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文