<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
    當首次作Insertupdatedeleteselect時,新產生的object在session關閉之前將自動裝載到session級別的緩存區,如果,AP使用了二級緩存,同樣也會裝入到二級緩存。所以當數據量大時,就會出現outofmemory情況。
    1.批理插入
        方式一:
            在hibernate.cfg.xml中設置批量尺寸
            <property name="hibernate.jdbc.batch_size">50</property>
            關閉二級緩存
            <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進行批量插入
            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>
        如,批量更新所有顧客聯系電話中的空格
     方式一:
       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 長春語林科技 閱讀(3048) 評論(0)  編輯  收藏 所屬分類: hibernate
    <2008年5月>
    27282930123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

     

    長春語林科技歡迎您!

    常用鏈接

    留言簿(6)

    隨筆分類

    隨筆檔案

    文章分類

    文章檔案

    相冊

    收藏夾

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 黄网站色视频免费观看45分钟| 综合自拍亚洲综合图不卡区| 亚洲狠狠色丁香婷婷综合| 91久久青青草原线免费| 亚洲精品~无码抽插| aa午夜免费剧场| 亚洲中文字幕无码爆乳AV| 日本中文字幕免费看| 亚洲精品国产福利一二区| 免费的黄网站男人的天堂| 亚洲精品国产va在线观看蜜芽| 成年免费a级毛片| 国产亚洲精久久久久久无码77777 国产亚洲精品成人AA片新蒲金 | 亚洲AV无码成人专区片在线观看 | 大地影院MV在线观看视频免费| 亚洲色婷婷综合开心网| jizz免费在线影视观看网站| 国产亚洲精品无码成人| 日本在线免费播放| 亚洲第一页在线观看| 夜夜嘿视频免费看| 一区二区三区在线免费| 久久精品国产亚洲综合色| 18禁男女爽爽爽午夜网站免费| 亚洲中文无码a∨在线观看| 好爽好紧好大的免费视频国产| 免费无码国产在线观国内自拍中文字幕| 亚洲一区二区三区免费| 日本一卡精品视频免费| 国产成人亚洲精品| 亚洲第一黄片大全| 99精品视频在线免费观看| 亚洲日本VA午夜在线电影| 亚洲性在线看高清h片| 免费国产黄网站在线观看| 亚洲精品中文字幕| 亚洲综合日韩久久成人AV| 2021国产精品成人免费视频| 免费精品国产自产拍在线观看| 亚洲AV无码国产精品色午友在线| 免费理论片51人人看电影|