L1 cache in Hibernate
HibernateTest. java
code:
Operation effect:
As we will see, only one select statement is used here. But we read two records!
Why does this happen?
This is because hibernate uses L1 cache, which is also called session cache
During the lifetime of a session, the data he uses will be buffered. The data record numbered 2 is read for the first time
When reading for the first time, there is nothing in memory. At this time, a select statement is used to read a record from the database and put these data into the session cache
Next, the same data will be read. At this time, he will not read data from the database, but from the cache.
Get this object and return it, so we see a select statement
Sysout(true); Namely: GB = GB2
Operation effect:
We see that we want to update two new records, but only an update statement is executed here.
This is hibernate using cache. Just use an update.
HibernateTest. java
Operation effect:
log4j:WARN No appenders Could be found =?=?=?=?=?=?=?=?=?=?