hql 中不能写 select count( 0 ) 或 select count( 1 ) 来计数。但是能够写 select count( a.id ) 或 select count(*)
//第1种方法:
String hql = "select count( a.id ) from Business a";
//第2种方法:
String hql = "select count( * ) from User as user";
Query query = getHibernateTemplate().createQuery( hql );
return ( (Integer) query.uniqueResult() ).intValue();
本文介绍了在HQL中进行计数查询的两种有效方法,避免使用selectcount(0)或selectcount(1),而是采用selectcount(a.id)或selectcount(*)的方式,通过具体示例展示了如何使用Hibernate模板进行查询并获取结果。
305

被折叠的 条评论
为什么被折叠?



