<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 325,  comments - 25,  trackbacks - 0
    當(dāng)首次作Insertupdatedeleteselect時,新產(chǎn)生的object在session關(guān)閉之前將自動裝載到session級別的緩存區(qū),如果,AP使用了二級緩存,同樣也會裝入到二級緩存。所以當(dāng)數(shù)據(jù)量大時,就會出現(xiàn)outofmemory情況。
    1.批理插入
        方式一:
            在hibernate.cfg.xml中設(shè)置批量尺寸
            <property name="hibernate.jdbc.batch_size">50</property>
            關(guān)閉二級緩存
            <property name="hibernate.cache.use_second_level_cache">false</property>
        Session session=SessionFactory.openSession();
        Transaction tx=session.beginTransaction();
        for(int i=0;i<1000;i++)
        {
            Customer customer=new Customer();
             session.save(customer);
        if(i%50==0)
            {
                session.flush();
                session.clear();
              }
         }
            tx.commit();
            session.close();

    方式二:繞過hibernate,直接使用JDBC進(jìn)行批量插入
            Session session=SessionFactory.openSession();
        Transaction tx=session.beginTransaction();
        Connection conn=session.connection();
        PreparedStatement stmt=conn.prepareStatement("insert into orders(orderno) values (?)");
        for(int i=0;i<1000;i++)
        {
            stmt.setString(1,"a"+i);
            stmt.addBatch();
        }
        stmt.executeBatch();
        ts.commit();
        session.close();
    二、批量更新
        hibernate.cfg.xml中配置:
        <property name="hibernate.query.factory_class">org.hibernate.hql.ast.ASTQuetyTranslatorFacotry</property>
        如,批量更新所有顧客聯(lián)系電話中的空格
     方式一:
       Session session=SessionFactory.openSession();
        Transaction tx=session.beginTransaction();
        Query query=session.createQuery("update Customer set phone=Trim(phone)");
        query.executeUpdate();
        tx.commit();
        session.close();
    方式二:繞過hibernate,通過jdbc
        Session session=SessionFactory.openSession();
        Transaction tx=session.beginTransaction();
         Connection conn=session.connection();
        Statment stmt=conn.createSatement();
        stmt.executeUpdate("update Customer set phone=Trim(phone)");
        tx.commit();
        session.close();
    三、批量刪除
        hibernate.cfg.xml中配置:
        <property name="hibernate.query.factory_class">org.hibernate.hql.ast.ASTQuetyTranslatorFacotry</property>
        如,批量更刪除所有ID小于5000的顧客
     方式一:
       Session session=SessionFactory.openSession();
        Transaction tx=session.beginTransaction();
        Query query=session.createQuery("delete Customer where id<5000");
        query.executeUpdate();
        tx.commit();
        session.close();
    方式二:繞過hibernate,通過jdbc
        Session session=SessionFactory.openSession();
        Transaction tx=session.beginTransaction();
         Connection conn=session.connection();
        Statment stmt=conn.createSatement();
        stmt.executeUpdate("delete from Customer where id<5000");
        tx.commit();
        session.close();
    posted on 2008-05-25 23:01 長春語林科技 閱讀(3053) 評論(0)  編輯  收藏 所屬分類: hibernate
    <2008年5月>
    27282930123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

     

    長春語林科技?xì)g迎您!

    常用鏈接

    留言簿(6)

    隨筆分類

    隨筆檔案

    文章分類

    文章檔案

    相冊

    收藏夾

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 国产精品成人啪精品视频免费| 亚洲国产日韩一区高清在线 | 99爱视频99爱在线观看免费| 亚洲sm另类一区二区三区| 亚洲av午夜福利精品一区人妖| 四虎影院永久免费观看| 精品久久8x国产免费观看| 久青草视频在线观看免费| 亚洲成a∨人片在无码2023| 亚洲成人福利在线| 黑人精品videos亚洲人| 四虎永久免费影院| 在线观看免费精品国产| 免费精品国产自产拍在线观看图片| 免费人成黄页在线观看日本| 免费无码婬片aaa直播表情| 亚洲综合在线一区二区三区| 亚洲无限乱码一二三四区| 国产精品亚洲片在线观看不卡| 亚洲av无码乱码在线观看野外| 美女视频黄免费亚洲| 亚洲麻豆精品果冻传媒| 亚洲AV无码专区电影在线观看| 毛茸茸bbw亚洲人| 亚洲v国产v天堂a无码久久| 日本大片在线看黄a∨免费| 亚洲免费网站观看视频| 亚洲AV无码成人精品区天堂| 免费少妇a级毛片人成网| 亚洲国产成人精品激情| 亚洲av无码国产精品色在线看不卡| 国产成人精品免费视频网页大全| 美女视频黄的免费视频网页| 久久久WWW免费人成精品| 高清免费久久午夜精品| 香蕉视频免费在线播放| 免费在线观看日韩| 免费无码一区二区三区蜜桃大| 天天摸天天碰成人免费视频| 女性自慰aⅴ片高清免费| 午夜网站免费版在线观看|