First-level caching (view the SQL statement on the console when executing code)
Empty Cache
@Test
public void demo03 () {
Empty cache
Session session=factory.opensession ();
Session.begintransaction ();
1. Enquiry
User user = (user) Session.get (user.class, 1);
SYSTEM.OUT.PRINTLN (user);
SESSION.EVITC (user)//Remove the execution object from the first-level cache
Session.clear (); Empty the first-level cache of all content
Session.close (); The session is closed and cannot be manipulated, otherwise the exception will be thrown. If session is closed, first-level cache is destroyed and data cannot be shared with another session
2. Re-query--The default is to get the content from the first level cache
User User1 = (user) Session.get (user.class, 1);
System.out.println (user1);
Session.gettransaction (). commit ();
Session.close ();
}
Snapshot
Snapshot: A backup of the same data in the first-level cache, which cannot be manipulated directly by the API, and Hibernate maintains itself. Used to align data in a first-level cache with a database
Swipe out cache: Indicates that the first-level cache is compared to the snapshot.
Modify the Flash cache time: Flushmodel to set.
1.get query, Results Store First level cache
2. Modify the content. User.setusername ("Jack");//Data inconsistency
3.1 When query is executed, the UPDATE statement is executed first, and the query is up to date.
3.2 Transaction.commit (): Go to refresh when executing commit
3.3 Session.flush () manually refreshes the cache
API
Save. To cache the transient object in a persistent state object
Primary key generation policy native: When the Save method is executed, insert is triggered, the data is generated OID, and the data is entered into the database after commit
Primary key generation policy assigned: You must manually set the OID and then execute save when the insert is triggered when committed
Update: the de-tube transformation lasts
Update Database with OID
Hibernate Session Cache