hql group by使用 (HibernateCallback())

	private List findListForGroup(final String hql,HttpServletRequest req, HttpServletResponse resp){
		ServletContext sc = req.getSession().getServletContext();
		ApplicationContext ac = WebApplicationContextUtils.getWebApplicationContext(sc);
		SessionFactory sessionFactory=(SessionFactory) ac.getBean("sessionFactory");
		HibernateTemplate hibernateTemplate=new HibernateTemplate(sessionFactory);
		List list = hibernateTemplate.executeFind(new HibernateCallback()
		{
			public Object doInHibernate(Session session)throws HibernateException,SQLException {
			    Query query = session.createQuery(hql);//创建SESSION
			    List list = query.list();
			    return list;//返回值
			}
		});
		return list;
	}

你可能感兴趣的:(Hibernate)