天天看點

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));