hql你就直接写就行,笨方法就是查询所有的,放在List集合里,然后list.size就得到数据库表的总记录数了啊 要非写hql语句的话 它和sql语句是一样的SELECT count(*) FROM 类名
select * from table
where rownum<(select count(*)+1 from table)
minus
select * from table
where rownum<(select count(*) from table)
也可以简化为
select * from table
minus
select * from table
where rownum<(select count(*) from table)
效果是一样的
切记rownum是伪列 只能用<
顺便给你求第X行的通用SQL语句
select * from table where rownum
select * from table where rownum
String hql ="SELECT count(u) FROM User u";
Query query = session.createQuery(hql);
Integer count = query.uniqueResult();
String hql = "select count(*) from User u";
session.createQuery(hql).uniqueResult();
这里返回Object,你想转int 或 long 随你。