spring data JPA entityManager查詢 並將查詢到的值轉為實體物件
阿新 • • 發佈:2019-01-03
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));