Some explanations about lazy attributes in hibernate

Source: Internet
Author: User
The average person does know that lazy is used to control the delayed loading and loading immediately, without considering why it is used.
In hibernate3.0, lazy has three values: True, false, and proxy. The default value is lazy = "proxy ".
The specific setting depends on your needs. It doesn't mean that the setting is the best.
Suppose that the student object contains a head object
If you are sure you want to use the attributes in the head object when using the student object, you can set to load immediately, because it is set to load immediately, the head of student will be queried at the same time as the student is queried, and hibernate will associate two tables during the query to generate only one SQL statement. If you set delayed loading, one or more SQL statements will be generated: "1" is the statement used to query student, "N" is to query n statements of the head based on N student IDs. In addition, delayed loading is used to execute the query. In this way, the system determines that loading is required, and loading is not required or takes time. The performance is definitely better than loading immediately!
If you need to use the head attribute only when student is used, you can set it to delayed loading, because it is certainly more expensive to query the data of two tables than to query one table.
It depends on your actual needs.

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.