Hibernate纯sql查询VO对象封装
hibernate 纯sql查询返回结果集(未关联映射)组装VO的问题
//须保证别名字段与Vo字段一致
//引号中为vo对象属性需与sql查询返回字段一致
.addScalar("chname").setResultTransformer(Transformers.aliasToBean(Vo.class))
例:
@Override
public List<EmployeeGroupVo> selectLeaderEmpRef(String leid) {
String sql = "SELECT e.uid as uid,e.uid as eid,e.employee_name as chname,l.employee_id as leid,g.group_name as gname FROM t_employee as e,t_group as g,t_group_leader l where e.group_id=g.uid and l.group_id=g.uid";
Query query = hibernateTemplate.getSessionFactory().getCurrentSession().createSQLQuery(sql).addScalar("uid").addScalar("eid")
.addScalar("chname").addScalar("leid").addScalar("gname").setResultTransformer(Transformers.aliasToBean(EmployeeGroupVo.class));
List<EmployeeGroupVo> list = query.list();
return list;
}