天天看点

JPA 查询原生SQL 转换VO对象

List<String> sqlList = RiverCourseSql.getRiverCourseSQLString(new RiverCourseDataQO());
        List<RiverCourseDataVO> riverCourseDataVO = rsvrfsrBDao.executeNativeQuery2Obj(sqlList.get(0), new PageQO(), RiverCourseDataVO.class);
           

查询sql,然后执行功能方法。

<E> List<E> executeNativeQuery2Obj(String sql, SortQO sortQO, Class<E> clz);

public <E> List<E> executeNativeQuery2Obj(String sql, SortQO sortQO, Class<E> clz) {
        Query query = this.entityManager.createNativeQuery(sql);
        this.setAliasParameter(query, sortQO);
        ((NativeQueryImpl)query.unwrap(NativeQueryImpl.class)).setResultTransformer(Transformers.aliasToBean(clz));
        List<E> resultList = query.getResultList();
        return resultList;
    }