天空是蓝色的

做好软件为中国 #gcc -c helloworld.c -o helloworld.o //编译目标文件 #gcc helloworld.o -o helloworld //编译成可执行exe #helloworld //运行exe
数据加载中……
修正一下Hibernate取count(*)的方法
    public int getCount(String emailGroupId, String emailBatchId)
            
throws HibernateException {

        Session session 
= HibernateUtil.currentSession();
        Transaction tx 
= session.beginTransaction();

        String hql 
= "select count(*) from EmailSendInfo where email_group_id = :emailGroupId and batch_id = :batchId";
        Query query 
= session.createQuery(hql);

        query.setString(
"emailGroupId", emailGroupId);
        query.setString(
"batchId", emailBatchId);
        
/*
         * for (Iterator it = query.iterate(); it.hasNext();) { return
         * ((Integer) it.next()).intValue(); }
         
*/

        
try {
            
return ((Integer) query.iterate().next()).intValue();
        }
 catch (Exception e) {
            
throw new HibernateException("");
        }
 finally {
            tx.commit();
            HibernateUtil.closeSession();
        }

    }

posted on 2005-12-22 14:20 bluesky 阅读(3331) 评论(3)  编辑  收藏 所属分类: 工作总结

评论

# re: 修正一下Hibernate取count(*)的方法 2007-01-11 11:18 漂泊

很好,谢谢,找了半天了!
终于可以了
  回复  更多评论    

# re: 修正一下Hibernate取count(*)的方法 2007-09-14 14:32 XT

为什么我这样写,它却总是报
return ((Integer) query.iterate().next()).intValue();
这句话类型转换错误呢?
  回复  更多评论    

# re: 修正一下Hibernate取count(*)的方法[未登录] 2007-09-18 22:33 bluesky

是不是你的数量太大了,超过了Integer类型的范围了,试下Long?
  回复  更多评论    

只有注册用户登录后才能发表评论。


网站导航: