spring data jpa 查询时的统计
原创
©著作权归作者所有:来自51CTO博客作者山阳糊涂的原创作品,请联系作者获取转载授权,否则将追究法律责任
public List<SimpleCity> listByProvinceId(int provinceId) {
EntityManager em = entityManagerFactory.createEntityManager();
Query query = em.createQuery("select new com.jiapeng.xfw.server.normalClass.SimpleCity(c.province.id,c.province.name,c.id,c.name,c.distList.size) " +
"from City c where c.province.id =? order by c.id");
query.setParameter(1,provinceId);
List<SimpleCity> list = query.getResultList();
em.close();
return list;
}
c.distList.size就是统计的,在City类中定义的属性是这样的
@OneToMany(mappedBy = "city")
private