没有其它办法了,
可以iterator出来,不过效果和select count(id) 差不多
 getHibernateTemplate()返回的都是list,没有单个的

解决方案 »

  1.   

    String condi1, String condi2
    要声明为final,否则方法内部类不能访问这个变量
      

  2.   

    Integer v = (Integer) getHibernateTemplate().execute
    你的是.executeFind这样返回的是List,不行的!!!
      

  3.   


    效率应该还可以  就跟你直接使用SQL语句一样count(*)和count(id)的效率其实都是差不多的
      

  4.   

    想要count(*)还是用session吧,其他的地方用getHibernateTemplate就好
      

  5.   


    public int getCount(String condi1, String condi2) {
          return (Integer)getHibernateTemplate().executeFind(new HibernateCallback() {
                public Object doInHibernate(Session s) throws HibernateException,
                        SQLException {
                    String q = "select count(id) from Table where " + condition1
                            + "=" + condi1;
                    Query query = s.createQuery(q);
                    return query.uniqueResult();
                }
            });
    }
    应该是这样吧