天空是藍色的

          做好軟件為中國 #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 閱讀(3378) 評論(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?
            回復  更多評論    
          主站蜘蛛池模板: 柏乡县| 土默特右旗| 玛沁县| 聊城市| 梓潼县| 安吉县| 江油市| 祁连县| 辽宁省| 仙居县| 徐汇区| 蚌埠市| 怀集县| 岑溪市| 罗定市| 望都县| 莱西市| 衡水市| 喀喇| 游戏| 拉萨市| 南雄市| 肇东市| 阿克陶县| 白朗县| 明溪县| 昭苏县| 临沭县| 洱源县| 开鲁县| 绥宁县| 政和县| 禄丰县| 策勒县| 丰城市| 嘉兴市| 绥宁县| 宁阳县| 昔阳县| 杭锦旗| 大名县|