天天看点

spring data JPA entityManager查询 并将查询到的值转为实体对象

String sql="Select f.*,c.name fname,c.phone from e_financial_products f "

                + "left join e_financial_products_consultant c on f.id=c.product_id "

                + "where f.type_two=?1";

        List<FinancialProductsBeanTest> list=entityManager.createNativeQuery(sql)

             //设置参数

                .setParameter(1, typeTwo) 

                .unwrap(org.hibernate.Query.class)

                .setResultTransformer(Transformers.aliasToBean(FinancialProductsBeanTest.class)).list();

        System.out.println(JSON.toJSONString(list));