To verify the existence of a cache in hibernate using the Process method

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.