本地原生SQL:
SELECT pole.pId as poleId FROM lamppole pole LEFT JOIN grouppole gp ON pole.pId = gp.pId
Query:
Query q = getSession().createSQLQuery(sql2.toString()).addScalar("poleId")
.setResultTransformer(Transformers.aliasToBean(TestDto.class));
如果SQL有别名,那么,query就一定要加
addScalar("别名")
不然抛此异常:
could not read column value from result set column 'pId' not found