標籤: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二級緩衝:集合緩衝區特點