Home » Java » Hibernate's crawl strategy II

Hibernate's crawl strategy II

Hibernate crawling strategy

@ sunRainAmazing


Fetching strategies
The
 grab strategy (fetching, strategy) means:
When an application needs to navigate between relational associations (Hibernate entity object diagrams),
How Hibernate obtains the associated object policy. The crawl policy can be declared in the metadata of the O/R map,
You can also overload declarations in a particular HQL or conditional query (Criteria, Query)
By configuring the fetching strategy, the query efficiency of the get () and the load () methods of Session can be directly affected by

Four grasp strategies for Hibernate performance tuning"
 connection crawl (Join fetching)
- Hibernate uses OUTER JOIN in the SELECT statement
(outer join) to obtain the associated instance or association set of an object
Query fetching (Select, fetching)
In addition, sends a SELECT statement to grab the associated entity or collection of the current object
Unless you explicitly specify lazy= "false", fetching (lazy) is prohibited,
Otherwise, only second select statements will be executed only when you really access relational relationships
Fetching (Subselect)
Also, send a SELECT statement to crawl to (or grab) the previous query
An associative collection of all solid objects of an object
Unless you explicitly specify lazy= "false", fetching (lazy) is forbidden,
Otherwise, only second select statements will be executed only when you really access relational relationships
Batch capture (Batch, fetching) -
The optimization scheme for query fetching by specifying a primary key or a list of foreign keys,
Hibernate uses a single SELECT statement to obtain a batch of objects, instances, or collections
1. it is very important to develop reasonable crawling strategy to improve the performance of the system
The Hibernate recommendation is that, typically, we do not use mapping documents for customization of fetching policies
More, keep its default value, and then in a specific transaction,
Use HQL's left left fetch (join) to overload it
Hibernate's recommendation is also best practice:
Make all the objects associated with the crawl set to lazy, and then load them in a particular transaction!
This consideration is based on the fact that object graphs are complex,
Sometimes even if we're just eager load, an object can cause a lot of objects to come out of load!
In Hibernate, all object associations are lazy,
But JPA is different, and the default fetching strategy for one-to-one and many-to-one objects is eager!
Therefore, when using JPA @annotation, be sure to change the default mappings that are eager to lazy!

Latest