用Hibernate實現批量加載

          Posted on 2006-07-21 15:53 波波 閱讀(366) 評論(0)  編輯  收藏

          下面是一個用Hibernate實現對數據庫進行批量操作的示例

          public class AddMoreWords {

          ?private static String type = "idiom";
          ?/**
          ? * @param args
          ? */
          ?public static void main(String[] args) throws Exception {
          ??// TODO Auto-generated method stub
          ??
          ??Session session = HibernateSessionFactory.currentSession();
          ??Transaction txc = session.beginTransaction();
          ??for(int i=0;i<1000;++i){
          ???WordLib word = new WordLib();
          ???word.setChn("mm"+(i+1));
          ???word.setTime(new Date());
          ???word.setType(type);
          ???session.save(word);
          ???if((i+1)%25 == 0){
          ????session.flush();
          ????session.clear();
          ???}
          ??}
          //??WordLib word = new WordLib();
          //??word.setChn("a");
          //??word.setTime(new Date());
          //??word.setType(type);
          //??session.save(word);
          ??txc.commit();
          ??HibernateSessionFactory.closeSession();
          ??session.flush();
          ??session.close();
          ?}

          }


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           

          posts - 1, comments - 0, trackbacks - 0, articles - 0

          Copyright © 波波

          主站蜘蛛池模板: 大埔县| 千阳县| 同江市| 姚安县| 漳浦县| 大姚县| 会泽县| 贡嘎县| 靖西县| 大足县| 洪泽县| 南通市| 抚远县| 通渭县| 锦屏县| 西丰县| 连平县| 清水县| 桃源县| 连山| 遂川县| 永昌县| 侯马市| 高要市| 托克逊县| 上高县| 胶南市| 江北区| 芷江| 时尚| 报价| SHOW| 垣曲县| 新民市| 明水县| 门源| 牟定县| 沾化县| 如东县| 宣化县| 彭山县|