hibernate学习笔记
在hibernate中使用groupby语句返回自定义的对象的时候,返回的格式是List<Object[]>
可以使用如
resultList.get(0)[0]去获得对应的对象的值
调用group by的代码
List<Object[]> resultList = openSessionFactory.groupby("book.id,count(*) as count", "BookLendRecord", "book.id");
System.out.println(resultList.get(0)[0]);
groupby的源码
public static List groupby(String need,String table,String column){
before();//获得session
String hql = "select "+need+" from "+table+" obj group by obj."+column;
org.hibernate.Query query = session.createQuery(hql);
List result = query.list();
after();
return result;
}