Hibernate (11) Search and hibernate search
I. Hibernate search policy
Ii. search methods
3. get and load comparison
Difference between get and load:
Get does not support delayed loading, but load does.
When querying data that does not exist in a specific database, get returns null, while load throws an exception.
Delayed loading of classes:
Set lazy = "true" in the <class> label or keep the default value (that is, do not configure the lazy attribute)
If the value of lazy is true, SQL statements are issued only when the load method is used to load data. This may reduce the overhead of the system.
// No query SQL will be issued
System. out. println ("group id =" + group. getId ());
Here is a question: why do I not need to issue an SQL statement when loading the primary key.
The select query is not executed. Instead, the group class proxy instance is created and only the OID attribute is initialized,
Databases are not queried when accessing the OID primary key attribute of the group class.
The SQL query database is executed only when the non-OID attribute is accessed for the first time.
Iv. fetch
5. lazy delayed Loading
Lazy, delayed Loading
Lazy's validity period: valid only when the session is opened; lazy does not work after the session is closed.
5.1 lazy policies can be used in:
- <Class> label: Optional values: true/false
- <Property> A tag can be set to true or false. This feature requires class enhancement.
- Set <set>/<list> to true/false/extra.
- For <one-to-one>/<others-to-one> and other labels, you can set the value to false/proxy/no-proxy.
5.2 set lazy = false on the set
- True: the default value. It means that the query statement is issued only when the set is called to obtain the element objects, and the data of the element in the set is loaded.
- False: cancels the lazy loading feature, that is, when an object is loaded, the second query statement is sent to load the data of its associated set.
- Extra: A clever lazy loading policy, that is, when calling methods such as size/contains of a set, hibernate
Instead of loading the data of the entire set, a clever SQL statement is issued to obtain the required value. Only when the data of these set element objects is actually needed, to load the data of all objects.
5.3. Hibernate single-ended associated lazy loading policy: You can configure it on the <one-to-one>/<allow-to-one> label.
- Lazy loading policy. Optional values: false/proxy/no-proxy
- False: cancels the lazy loading policy. When an object is loaded, the system issues a query statement to load its associated objects.
- Proxy: This is the default lazy loading policy of hibernate for single-ended associations. That is, only when the method of its associated object is called can a query statement be issued to query its object data. The associated object is a proxy class.
- No-proxy: This lazy loading feature requires class enhancement. When no-proxy is used, its associated object is not a proxy class.
Note: The lazy attribute configured on the class label does not affect the associated object !!!