day37 03-Hibernate二級緩衝:集合緩衝區特點

來源:互聯網
上載者:User

標籤:from   資料   nat   技術分享   .com   str   設定檔   核心   bsp   

所以說要經常檢查hibernate3的核心設定檔hibernate.cfg.xml.

 

Hibernate:
select
customer0_.cid as cid0_0_,
customer0_.version as version0_0_,
customer0_.cname as cname0_0_,
customer0_.age as age0_0_
from
customer customer0_
where
customer0_.cid=?
Hibernate:
select
orders0_.cno as cno0_1_,
orders0_.oid as oid1_,
orders0_.oid as oid1_0_,
orders0_.addr as addr1_0_,
orders0_.cno as cno1_0_
from
orders orders0_
where
orders0_.cno=?

訂單的數量:11

這是咱們的預設情況,fetch="select" lazy="tue"的情況。這種情況發多條SQL語句。所以不是串連查詢,而是分步單表查詢。

向下執行,查詢customer2沒有發SQL,因為使用了二級緩衝。再向下執行查詢customer2的訂單也沒有發SQL,跟hibernate3核心設定檔hibernate.cfg.xml中的一句話:<collection-cache usage="read-write" collection="cn.itcast.hibernate3.demo1.Customer.orders"/>有關。集合緩衝區 所以在獲得客戶的訂單的數量的時候,就沒有再去發送SQL語句了。因為它已經把我們的集合orders也給緩衝了。集合緩衝區用來緩衝對象中的集合。我們現在用的就是對象中的集合,所以它沒有發送SQL語句。

現在要證明集合緩衝區的資料是依賴於類緩衝區的。嘗試注釋掉<collection-cache usage="read-write" collection="cn.itcast.hibernate3.demo1.Customer.orders"/>這句話。

Hibernate:
select
customer0_.cid as cid0_0_,
customer0_.version as version0_0_,
customer0_.cname as cname0_0_,
customer0_.age as age0_0_
from
customer customer0_
where
customer0_.cid=?
Hibernate:
select
orders0_.cno as cno0_1_,
orders0_.oid as oid1_,
orders0_.oid as oid1_0_,
orders0_.addr as addr1_0_,
orders0_.cno as cno1_0_
from
orders orders0_
where
orders0_.cno=?
訂單的數量:11
Hibernate:
select
orders0_.cno as cno0_1_,
orders0_.oid as oid1_,
orders0_.oid as oid1_0_,
orders0_.addr as addr1_0_,
orders0_.cno as cno1_0_
from
orders orders0_
where
orders0_.cno=?
訂單的數量:11

取消了集合緩衝區的話查詢customer2不會發SQL(因為customer2使用了二級緩衝)。而查詢customer2的訂單就會發SQL(因為取消了集合緩衝區)。

day37 03-Hibernate二級緩衝:集合緩衝區特點

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.