Lazy loading and Fetch in Hibernate

Source: Internet
Author: User

Lazy Loading in Hibernate

1. Class-level query policy:

Lazy:true (default value)

False (Load Now)

2. Many-to-one associated query strategy:

Lazy:proxy (default value)

No-proxy

False

3. One-to-many or many-to-many

Lazy:true (default value)

False

Extra

Fetch: Affects hibernate generation for the underlying SQL

First, the class level of the EMP mapping file is set to non-lazy loading

The second one will report a null pointer exception

Second, the EMP mapping file class level set non-lazy loading, its many-to-one property is also set to non-lazy loading

Test code

Third, the EMP mapping file class level set non-lazy load, many to one node set delay loading and fetch= "join"

conclusion 1: When fetch and lazy are in the same time, set fetch= "join", the lazy properties will lose its function, that is no longer guaranteed non-lazy loading, but immediately loaded

Iv. when using the list () method of the query interface, the fetch= "join" lazy property is re-enforced


Conclusion: Using the list () method of the query interface, fetch= "join", the Lazy property is re-effective, which is determined by the mechanism of the list itself, list can only put data into memory, cannot fetch data from memory, must force access to the database

Lazy loading and Fetch in Hibernate

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.