在使用hibernate的HibernateTemplate回调函数执行标准sql查询时,如:
List list = getHibernateTemplate().executeFind(new HibernateCallback() {
public Object doInHibernate(Session session) throws HibernateException, SQLException {
Query query = session.createSQLQuery(sql);
query.addScalar("EPeopleId",Hibernate.STRING)
.addScalar("archiveCode",Hibernate.STRING)
.addScalar("cnName",Hibernate.STRING)
.addScalar("sex",Hibernate.STRING)
.addScalar("idCard",Hibernate.STRING)
.addScalar("tel",Hibernate.STRING)
.addScalar("xjLevel1Id",Hibernate.STRING)
.addScalar("xjLevel2Id",Hibernate.STRING)
.addScalar("controlLevel1Id",Hibernate.STRING)
.addScalar("controlLevel2Id",Hibernate.STRING)
.addScalar("specialControlLeveId",Hibernate.STRING)
.addScalar("globalUnitCode",Hibernate.STRING);
return query.list();
}
});
切记要为SQLQuery对象添加查询结果列属性。