天空是藍色的

          做好軟件為中國 #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 閱讀(3383) 評論(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?
            回復  更多評論    
          主站蜘蛛池模板: 赤水市| 合水县| 涟源市| 阿拉善盟| 屏东县| 阿图什市| 临夏市| 大竹县| 巴林左旗| 镇巴县| 新巴尔虎右旗| 准格尔旗| 三原县| 依安县| 莒南县| 柞水县| 苍南县| 绵阳市| 天峻县| 南昌市| 淮阳县| 六枝特区| 威宁| 黔东| 天峻县| 奎屯市| 永德县| 共和县| 盐亭县| 铜梁县| 石台县| 峨山| 凌云县| 乳山市| 同江市| 色达县| 余江县| 桃园市| 射阳县| 景宁| 兰考县|