1, the test list and the relationship between Iterator and cache
(1), in the same session in the first iteration and then list
The results of the implementation is:
Hibernate:
select
book0_.BID as col_0_0_
from
T_BOOK book0_
Hibernate:
select
book0_.BID as BID3_0_,
book0_.BNAME as BNAME3_0_
from
T_BOOK book0_
where
book0_.BID in (
?,?
)
java
oracle
Hibernate:
select
book0_.BID as BID3_0_,
book0_.BNAME as BNAME3_0_
from
T_BOOK book0_
where
book0_.BID in (
?,?
)
c
. Net
***************************
Hibernate:
select
book0_.BID as BID3_,
book0_.BNAME as BNAME3_
from
T_BOOK book0_
java
oracle
c
. Net
Analysis: first iteration, we will query the database in an oid in the cache data to create a proxy object
When the iterator call next () method when the proxy object will be in accordance with each oid query the database and populate data
. When the iteration after the implementation of list time again, list directly to the database query to fill out an oid and data cache
, And did not go after one iteration from the data cache, query the database directly!
-------------------------------------------------- ----------------------------
(2), in the same session in the first list and then iterative
The results of the implementation is: Hibernate:
select
book0_.BID as BID3_,
book0_.BNAME as BNAME3_
from
T_BOOK book0_
java
oracle
c
. Net
***************************
Hibernate:
select
book0_.BID as col_0_0_
from
T_BOOK book0_
java
oracle
Analysis:
When the first list, to query the database directly, and the oid and data to fill in a cache to the
; Again after list. Continue to test only the implementation of Iterator when a oid the sql query statement, so that after a cache has been filled, Iterator on the need to create agents, but directly to the data out.
-------------------------------------------------- ----------------------------
(3) in the same session in the implementation of the two list
Query results is: Hibernate:
select
book0_.BID as BID3_,
book0_.BNAME as BNAME3_
from
T_BOOK book0_
java
oracle
c
. Net
***************************
Hibernate:
select
book0_.BID as BID3_,
book0_.BNAME as BNAME3_
from
T_BOOK book0_
java
oracle
c
. Net
Analysis: the two are the same sql on the implementation of the first list when filled to the level oid and data cache;
However, the implementation of the second list when the note or print the sql data to populate a list cache is not used!
But to rewrite the data into a database query!
Summary:
get and load
A, get
1, in the Book to find a cache proxy Proxy
2, If you do not go on to the database
3, if the data no data is returned null (this has nothing to do with a cache)
4, if the database data in a cache in the proxy object is created
(Which is filled with data, proxy)
B, load
1, if looking for a cache, if found to do nothing on the
2, If you can not find the words to create a proxy and set up OID (nothing to do with the database only with the level of the cache)
3, regardless of the proxy object is in any way, it will trigger the database to find (for example, call agent tostring)
list and Iterator
A, list will directly query the database to fill the oid and data cache is similar to a get; but found the cache after it came to no avail
B, Iterator queries directly to the creation of no data oid proxy object, when the call next () method will be based on the time of the first oid data to query the database to be filled
C, and the Iterator in the list after the re-implementation of load, the load will not print the sql statement
Second, hibernate performance optimization
1, lazy loading
A, when I Book.bhm.xml the class configuration file which will be set to false when the lazy, (do not call any method in the circumstances) will print out the query the database sql;
This shows that: if the lazy set to false, once the load time will be loaded with the oid and data will not be delayed
2, pre-loaded
1. Hql use the left join fetch to achieve
2, using the conditions of inquiry setFetchMode ( "multi-class", FetchMode. JOIN)
3, in the configuration file to write to fetch set to join







