This article for Bo Master original, allow reprint, but please declare the original address: http://www.coselding.cn/blog/8/8-142.html
- The HQL syntax is structured like a SQL statement,
- Query query = session.createquery (String HQL); A query object is obtained through a HQL query statement, which can get the result set of the HQL statement.
- Query supports internal links, left and right connections, supports direct queries to hibernate entity classes, and directly uses "." For other B entity class members in a entity class. To be called as a column of a entity class (an association relationship has been set);
- From,select,where,order By,group By, the subquery is the same as SQL, the specific query document
- The serial number is starting from 0 bits.
- Query.list data run out to Session.close ()
- Query supports normal SQL, HQL, EJBQL. Function Strength: nativesql>hql>ejbql>qbc>qbe.
- HQL placeholder: ": Parameter name" or "?", replacing the parameters in the placeholder directly with the Setinteger method.
- Paging: Setmaxresults: Sets the number of bars per page, Setfirstresult settings start from the first.
- You can return the property values for each column like SQL, and each property value is returned as an object, forming an object array. You can also compose a temporary wrapper object for these returned column values to save, and write "new class qualified name" in HQL.
- HQL with "join" to navigate the connection, join T.topic cannot use join Topic, because which object in T is to be set and Topic to connect.
- Query.uniqueresult (): Returns the query unique object.
- COUNT (*) returns a long type, with Query.uniqueresult ().
- Aggregate functions, Between...and, in, NOT null, is empty, is not empty, like, exists, not exists. the exists performs more efficiently than in.
- EJBQL commonly used functions, variable case, connection string, go space, average, sum, and so on. (Not important)
- The date is directly compared with >, <, and so on.
- Group BY, have, subquery, all functions.
- Namequery: Name the query, then call directly with key, @NameQueries define the named query, centralize the query statement management.
- Createsqlquery (): Use normal SQL statement query, return sqlquery, @NameNativeQueries.
- QBC (query by criterial): The criteria constraint set, with the restrictions to produce the query constraints, that is, where the clause, the equivalent of the SQL statement becomes object-oriented!!! Detachedcriteria: The object that creates the binding session can be separated from session management.
- QBE (Query by Example): Example e = Example.create (object obj), creating a constraint object that can be added as a constraint object of criteria to make object-oriented more thorough.
This article for Bo Master original, allow reprint, but please declare the original address: http://www.coselding.cn/blog/8/8-142.html
HQL Query Statements