hibernate 一級(jí)緩存

          1 hibernate 一級(jí)緩存
          Session?
          ? evict(Object o) 從緩存中清除指定的持久化對(duì)象
          ? clear()???????? 清除緩存中所有對(duì)象
          2 批量更新于批量刪除
          ? 1) 批量更新
          ?? Iterator customers=session.find("from Customer c where c.age>0");
          ?? while(customers.hasNext()){
          ???? Customer customer=(Customer)customers.next();
          ???? customer.setAge(customer.getAge()+1);
          ?? }
          ?? tx.commit();
          ?? session.close();

          ? 缺點(diǎn):內(nèi)存中加載了大量數(shù)據(jù)
          ??????? 執(zhí)行了多次update 語(yǔ)句
          ?
          ?? 改進(jìn)
          ?? Iterator customers=session.find("from Customer c where c.age>0");
          ?? while(customers.hasNext()){
          ???? Customer customer=(Customer)customers.next();
          ???? customer.setAge(customer.getAge()+1);
          ???? session.flush();
          ???? session.evict(customer);
          ?? }
          ?? tx.commit();
          ?? session.close();
          ?? 遺留問(wèn)題
          ?? 執(zhí)行了多次update 語(yǔ)句
          ??
          ?? 采用jdbc api 進(jìn)行調(diào)用
          ?? Connection con=session.connection();
          ?? PrepareStatement stmt=con.prepareStatement("update customers set age=age+1 where age>0");
          ?? stmt.executeUpdate();
          ?? tx.commit();
          ?? 另外,也可以調(diào)用底層的存儲(chǔ)過(guò)程進(jìn)行批量更新
          ?? create or replace procedure batchUpdateCustomer(p_age,in number) as
          ?? begin
          ????? update customer set age=age+1 where age>p_age;
          ?? end;
          ??
          ?? tx=session.beginTransaction();
          ?? Connection con=session.connection();
          ?? CallableStatement cstmt=con.prepareCall(batchUpdateCustomer);
          ?? cstmt.setInt(1,0);
          ?? cstmt.eqecuteUpdate();
          ?? tx.commit();
          ?? 2) 批量數(shù)據(jù)的刪除
          ??? session.delete("from? Customer c where c.age>0");
          ??? 實(shí)際調(diào)用的過(guò)程
          ??? session * from Customer where age>0;
          ??? 在把所有數(shù)據(jù)加載到內(nèi)存之后執(zhí)行多條delete 語(yǔ)句
          ??? delete from customer where id=i;
          ???? .......................
          ?? 改進(jìn)辦法采用jdbc api 進(jìn)行批量數(shù)據(jù)的刪除
          ?????
          ?? tx=session.beginTransaction();
          ?? Connection con=session.connection();
          ?? con.execute("delete from customers where age>0");
          ?? tx.commit();

          posted on 2006-09-14 09:22 康文 閱讀(471) 評(píng)論(0)  編輯  收藏 所屬分類: java

          <2006年9月>
          272829303112
          3456789
          10111213141516
          17181920212223
          24252627282930
          1234567

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿(1)

          隨筆分類

          隨筆檔案

          文章檔案

          搜索

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 黄山市| 昭平县| 个旧市| 云和县| 西青区| 清新县| 呼图壁县| 龙口市| 揭阳市| 华宁县| 临夏县| 铁岭县| 金溪县| 玉环县| 河南省| 溧阳市| 都安| 西乡县| 罗平县| 原阳县| 星座| 全州县| 宝山区| 腾冲县| 松溪县| 达尔| 旌德县| 乳源| 峡江县| 民勤县| 阿拉善右旗| 德惠市| 资兴市| 东乌| 平阳县| 茌平县| 社旗县| 安仁县| 惠水县| 泸水县| 陆川县|