悟心

          成功不是將來(lái)才有的,而是從決定去做的那一刻起,持續(xù)累積而成。 上人生的旅途罷。前途很遠(yuǎn),也很暗。然而不要怕。不怕的人的面前才有路。

            BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            93 隨筆 :: 1 文章 :: 103 評(píng)論 :: 0 Trackbacks
          批量插入(Batch inserts) 
          如果要將很多對(duì)象持久化,你必須通過(guò)經(jīng)常的調(diào)用 flush() 以及稍后調(diào)用 clear() 來(lái)控制第一級(jí)緩存的大小。 

          Session session 
          = sessionFactory.openSession(); 
          Transaction tx 
          = session.beginTransaction(); 
             
          for ( int i=0; i<100000; i++ ) { 
              Customer customer 
          = new Customer(..); 
              session.save(customer); 
              
          if ( i % 20 == 0 ) { //20, same as the JDBC batch size //20,與JDBC批量設(shè)置相同 
                  
          //flush a batch of inserts and release memory: 
                  
          //將本批插入的對(duì)象立即寫(xiě)入數(shù)據(jù)庫(kù)并釋放內(nèi)存 
                  session.flush(); 
                  session.clear(); 
              } 

             
          tx.commit(); 
          session.close(); 

          posted on 2010-07-30 17:17 艾波 閱讀(1595) 評(píng)論(0)  編輯  收藏 所屬分類: SS2H
          主站蜘蛛池模板: 汤原县| 河南省| 高淳县| 海林市| 鄱阳县| 北宁市| 平顺县| 徐水县| 娄烦县| 新干县| 谷城县| 临邑县| 清远市| 五家渠市| 海阳市| 盖州市| 化德县| 玉屏| 天水市| 江孜县| 广昌县| 舒兰市| 汉沽区| 竹北市| 合川市| 长子县| 东兰县| 杨浦区| 荣昌县| 屯留县| 甘肃省| 江阴市| 桂阳县| 大足县| 西乡县| 禄劝| 保定市| 襄垣县| 宁化县| 青岛市| 贵溪市|