The difference between get () and load () in Hibernate in shop++

Source: Internet
Author: User

This is I recently see shop++4.0 source experience Some of the things, because to do two times development, so first recorded.


1. Use the Load () method:
hibernate considers that the object (database record) corresponding to the ID must exist in the database, using a proxy to defer loading the object. The database is queried for other property data in the object, and if the record does not exist in the database, an exception is thrown, and the Load method throws an exception when the data from the object is used (called The Get () method to get the property), and the exception is thrown when the data does not exist in the database, rather than when the object is created. Due to the session cache problem, the session cache is checked at load to see if the object that corresponds to the ID exists, and if it does not exist, create the proxy. So if you know that the ID must have a corresponding record in the database, you can use the Load method to implement lazy loading.

2. Use the Get () method:
hibernate confirms the existence of the data for that ID, first in the session cache, then in the level two cache, and not on the database, which returns null in the database.

The difference between get () and load () in Hibernate in shop++

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.