JCS is an object cache that caches Java objects to increase access efficiency of Java objects that have high access frequencies. The JCS is to access objects in accordance with the unique indication of the object, such as accessible to the object's HashCode. For Hibernate, you can cache the query results, so when you access the same data, you don't need to go to the database, remove it directly from JCS, speed up the query speed. When Hibernate uses List or Iterator mode to read data for the first time, JCS is empty, at this time, no matter whether it is a LIST method or Iterator mode, populates the lasting object of Query in JCS, for example: SELECT C from cat as c
SELECT C.ID, C.Name from Cat As C
This HQL statement does not construct PO, so it will not fill the JCS. Ok, now the data is filled in the data, but what should I take? Above I have said it is to access according to the unique indication of the object, and for the PO persistent object, the only indication is the primary key, so Hibernate must first get the key list, and then judge according to the primary key list, see this persistent object is in The JCS is still in the database. If you are in the JCS, then follow the primary key, if you are in the database, send SQL take. Now let's analyze why Iterator can use JCS, and List can't. The above is said, before using JCS, you must first get a lasting object to take a lasting object in JCS, and how can we get the primary key list? You must go to the database, this step is no way to buffer. Hibernate Iterator's query itself is divided into two steps: ==> Select ID from cat
==> SELECT * from cat where id =?
==> SELECT * from cat where id =?
...
==> SELECT * from cat where id =?