Hibernate provides the following ways to retrieve objects
1) The Navigation object graph retrieves the way: navigates to other objects according to the already loaded object;
2)oid Retrieval Method: The object is retrieved according to the OID of the object;
3)hql retrieval Method: Using object-oriented HQL query language;
4)QBC Retrieval method: Use the QBC (Query by Criteria) API to retrieve the object. This API encapsulates query statements based on string forms and provides a more object-oriented query interface.
5) How local SQL is retrieved: SQL query statements that use local data.
HQL (Hibernate query Language) object-oriented query language, which is somewhat similar to the SQL query language. among the various retrieval methods provided by Hibernate, HQL is the most widely used method of retrieval. It has the following functions:
1) Set various query conditions in the query statement
2) Support projection query, that is to retrieve only some of the object's properties
3) Support Paged query
4) Support Connection query
5) Support for group queries, allowing the use of "having" and "Group BY" keywords
6) provides built-in aggregation functions such as SUM (), MIN (), Max ()
7) Support sub-query
8) Support Dynamic binding parameters
9) Ability to invoke user-defined SQL functions or standard SQL functions.
HQL retrieval methods include the following steps
1) Create a query object by using the CreateQuery () method of the session, which includes a HQL query statement. HQL can include named parameters in a query statement
2) Dynamic binding parameters
3) Call the query related method to execute the inquiry statement
Query interface support method chain programming style
Its setxxx () method returns its own instance, not the void type.
HQL vs SQL
1) HQL Query statement is object-oriented, hibernate is responsible for parsing HQL query statements, and then according to the object-relational mapping file mapping information, the HQL query statements translated into the corresponding SQL statement. HQL a topic in a query statement is a property of a class and class in a domain model
2) SQL query statements are bound to the relational database. The principal in the SQL query statement is the field of the database table and table.
Binding parameters
1) Hibernate's parameter binding mechanism relies on the PreparedStatement predefined SQL statement functionality in the JDBC API.
2) hql parameter binding in two forms:
Binding by parameter name: Define named parameters in the HQL query statement, named parameters with "." Beginning
Bind by parameter location: "?" in the HQL query statement To define the parameter position
3) Related parameters
Setentity (): Binds a parameter to a persistent class
Setparamenter (): Binds a parameter of any type, and the third parameter of the method explicitly specifies the Hibernate mapping class.
HQL sorting query results with the ORDER BY keyword
Hibernate (12): HQL query (i)