First, class-level query
1, get method: No policy, call immediately query database load data.
2, Load method: is executed without sending any SQL statements, return an object, use the object to execute the query, apply the class-level load policy.
1> Delay Loading: Only available, no use, no query, query when used
2> Lazy Loading of classes: You can control the load by configuring the Lazy property on the class element
Lazy (default): True when the query class returns a proxy object, the database is queried based on the associated session when the property is used, and the data is loaded
Do not query when loading, only query when using
lazy:false Query immediately when loading, no difference from Get method
Conclusion: Delayed loading (lazy loading) is recommended for increased efficiency
3> Note: When using lazy loading, make sure that the session is open when the call property loads the data, otherwise it throws an exception.
Second, relevance level query
1. Set Policy
Lazy property: Determines whether to delay loading
True (default): Lazy loading, lazily loading
False: Load Now
Extra: Extremely lazy, basically consistent with lazy loading effect
Fetch attribute: Determines the load policy, what type of SQL statement is used to load collection data
Select (default): Single-table query loading
Join: Loading a collection using a multiple-table query
Subselect: Loading a collection using a subquery
2. Association attribute Policy
Lazy attribute: Determines the loading time
False: Load Now
Proxy: Determined by the customer's class-level load policy
Fetch properties: Decide which SQL statement to load
Select: Use a single-table query
Join: Using multiple table queries
3. Conclusion
In order to improve efficiency, fetch should select Select,lazy should choose True, all using default values.
4, no-session problem solving
Expand the scope of the session
Third, Batch crawl
Batch-size: Fetching the number of collections
Grab a collection of contacts from several customers at a time when capturing a customer's collection
Hibernate framework Learning (10)--Query optimization