s1是什么东西?hsql的也支持普通的sql的呀,直接select count(*)就好了的

解决方案 »

  1.   

    Session s1 = HibernateUtil.currentSession();
    就是分页的时候希望能先取到表中的记录总数,最好是不用select count(*),不知有没有一个取得总记录数的方法,看了API,好象也没找到。
      

  2.   

    hsql = "select count(*) from LoveList"        
    return ((Integer)session.createQuery(hsql).iterate().next()).intValue();
      

  3.   

    用上边说的方法,没有问题,但是我要说的是对语句可以优化,select count(*) from LoveList改为:select count(id) from LoveList ,
    这里 id 是主键,当然,要根据你的实际情况写这个字段的名称。
      

  4.   

    /**
     * <p>
     * 对数据库进行操作,返回员工总人数 为分页提供服务
     * 
     * @return intcount
     * 
     */ public int count() throws Exception {
    log.warn("---->显示员工总人数");
    int counts;
    Session session = BaseHibernate.getSession();
    Integer count = (Integer) session.createQuery(
    "select count(*) from User s").uniqueResult();
    counts = count.intValue();
    BaseHibernate.closeSession(session);
    return counts;
    }