第一种方法:
String hql = "select count(*) from User as user";
Integer count = (Integer)getHibernateTemplate().find(hql).listIterator().next();
return count.intValue();
第二种方法:
String hql = "select count(*) from User as user";
return ((Integer)getHibernateTemplate().iterate(hql).next()).intValue();
第三种方法:
String hql = "select count(*) from User as user";
Query query = getHibernateTemplate().createQuery( getSession(),hql);
return ((Integer)query.uniqueResult()).intValue();