Write a small example of an enquiry
Test the existence of a first-level cache @Test public void Demo8 () { Session session = Hibernateutils.opensession (); Transaction Transaction = Session.begintransaction (); Book book = (book) Session.get (Book.class, "2c2882bc42f1e93b0142f1e93d2c0000"); SYSTEM.OUT.PRINTLN (book); System.out.println ("========================================================"); Execute the same query again-directly using the data in the first-level cache Book1 = (book) Session.get (Book.class, "2c2882bc42f1e93b0142f1e93d2c0000"); System.out.println (BOOK1); Transaction.commit (); Session.close (); }
Look at log.
14:43:04,171 Info tablemetadata:66-columns: [first_name, last_name]14:43:04,171 info tablemetadata:68- Foreign keys: []14:43:04,181 info tablemetadata:69-indexes: [primary]14:43:04,181 Info schemaupdate:217- Schema update completehibernate: select book0_.id as id1_0_, book0_.name as name1_0_, Book0_.price as price1_0_ from hbm3.tbl_book book0_ where book0_.id=? Book [id=2c2882bc42f1e93b0142f1e93d2c0000, Name=hibernate Primer Classic, price=23.0]======================================= =================book [id=2c2882bc42f1e93b0142f1e93d2c0000, Name=hibernate Introduction Classic, price=23.0]
For the first time, the SQL sentence was printed, and the second time there was no SQL language.
Say: The second time you haven't read the numbers from the DB, where did you get the numbers? is a level of cache, the first time to check the results of the inquiry has been put into a level of the second buffer to take out directly.
To verify the existence of a cache in hibernate using the Process method