<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 長春語林科技 閱讀(3047) 評論(0)  編輯  收藏 所屬分類: hibernate
    <2008年5月>
    27282930123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

     

    長春語林科技歡迎您!

    常用鏈接

    留言簿(6)

    隨筆分類

    隨筆檔案

    文章分類

    文章檔案

    相冊

    收藏夾

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲日韩久久综合中文字幕| 午夜神器成在线人成在线人免费 | 黄色网址在线免费观看| 亚洲精品中文字幕乱码| 国产亚洲午夜高清国产拍精品| 成人免费视频88| 波多野结衣免费在线| 亚洲一区免费观看| 香蕉免费在线视频| 人成午夜免费大片在线观看| 亚洲av永久无码精品网址| 亚洲人成网站在线观看播放动漫 | 国产免费A∨在线播放| 国产午夜亚洲精品不卡| 99亚偷拍自图区亚洲| 亚洲午夜久久久久久尤物| 亚洲午夜精品一区二区| 亚洲AV无码专区电影在线观看| 亚洲综合色自拍一区| 精品国产亚洲一区二区在线观看| 免费国产a国产片高清网站| 免费观看毛片视频| 暖暖日本免费在线视频 | 亚洲aⅴ天堂av天堂无码麻豆| 亚洲人成网站日本片| 亚洲综合色7777情网站777| 亚洲噜噜噜噜噜影院在线播放| 亚洲欧洲国产视频| 亚洲成a人片在线网站| 亚洲国产日韩在线一区| 亚洲另类视频在线观看| 亚洲一区二区三区高清不卡| 激情五月亚洲色图| 亚洲av无码成人影院一区| 在线观看亚洲网站| 一级特级aaaa毛片免费观看 | 亚洲电影日韩精品| 亚洲综合激情另类专区| 亚洲午夜国产精品无码| 久久噜噜噜久久亚洲va久| 亚洲高清视频在线播放|