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