天空是藍色的

          做好軟件為中國 #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 閱讀(3377) 評論(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?
            回復  更多評論    
          主站蜘蛛池模板: 炎陵县| 克东县| 西华县| 南漳县| 若尔盖县| 司法| 从江县| 昌图县| 金阳县| 伊金霍洛旗| 平度市| 北碚区| 岐山县| 林芝县| 中宁县| 托克逊县| 东海县| 东宁县| 新乐市| 互助| 周至县| 宜春市| 栾城县| 赤水市| 巴彦县| 乡城县| 嘉荫县| 冷水江市| 宜兴市| 望谟县| 马边| 汤阴县| 迭部县| 芦溪县| 古蔺县| 攀枝花市| 垣曲县| 新泰市| 东方市| 米脂县| 清河县|