c.customerid desc"). List(); }B, ASC Ascending Public Ilist Getcustomerbyorder () { return _session. CreateQuery ("fromcustomerentity C ORDER by c.customername ASC"). List(); }5. GROUP BY clause Public ilistObject[]> getcustomerbygroup () { return _ Session. CreateQuery ("Select C.customername, Count (C.customername) from the Customer C Group by C.customername "). listObject[]>(); }Second, in-depth expansion1. ConnectionA,inner join inside joins Public ilistObje
NET Pick one:
Sql:select c.* from card C left JOIN score s on s.card_id = C.id and S.invalid_date >=curdate () where s.id is nullTo use the LEFT join in hibernate you must declare an association mapping, where the association is One-to-many, a set scores is built in the card, and then configuredThe only special thing is that the WHERE,HQL cannot be written on, so the conditions on it are written in the where, where is the field name and the SQL for th
Hql functions and hql Functions
Serial number
Function Name
Description
Type
Supported
Usage
Remarks
1
ABS (n)
Take absolute value
Mathematical functions
JPAQL HQL
ABS (column_name [numeric object attributes])
2
SQRT (n)
Take the square root
Mathematical functions
JPAQL
Hibernate hql Query:The criteria query encapsulates the query criteria in an object-oriented manner, but HQL (Hibernate query lanaguage) queries provide richer and more flexible query features. As a result, Hibernate makes the HQL query the official recommended standard Query method, HQL query to cover all the function
HqlHql query:Criteria queries encapsulate the query conditions in an object-oriented manner and conform to the programming mindset. However, hql (Hibernate query language) queries provide richer and more flexible query features, therefore, Hibernate sets the hql query method as the standard query method officially recommended. hql queries provide a query method s
hql QueryHQL query:The criteria query encapsulates the query criteria in an object-oriented manner, but HQL (Hibernate query lanaguage) queries provide richer and more flexible query features. As a result, Hibernate makes the HQL query the official recommended standard Query method, HQL query to cover all the functions
Hql query:
Criteria queries encapsulate the query conditions in an object-oriented manner and conform to the programming mindset. However, hql (Hibernate query language) queries provide richer and more flexible query features, therefore, Hibernate sets the hql query method as the standard query method officially recommended.
= session.createquery (HQL); 3 List results = query.list ();Using paged queriesHere are two ways to page through the query interface:
S.N.
Method Description
1
Query setfirstresult (int startposition)The method represents the first row in the result as an integer, starting with 0 rows.
2
Query setmaxresults (int maxresult)This method tells Hibernate to retrieve a fixed number, that
Hibernate HQL Query Statement summary1, Entity query:As for the entity query technology, we have already dealt with it many times before, such as the following example:String hql= "from user User";List list=session. CreateQuery (HQL). List ();The result of the above code execution is that all data corresponding to the user entity object is queried, and the data i
-4.2.1.final\project\etc\hibernate.properties.template Or Configurable property values in the Hibernate-release-4.2.1.final\project\etc\hibernate.properties file Iii. named parameters of HQLExample:/*** Use HQL according to the name Query method* @param entity*/public static void Query (String name) {Session s = null;try {S=hibernateutil.getsession ();HQL:The from behind is not the table name, but the object name (class name)String
1, Entity query:As for the entity query technology, we have already dealt with it many times before, such as the following example:String hql= "from user User";List list=session. CreateQuery (HQL). List ();The result of the above code execution is that all data corresponding to the user entity object is queried, and the data is encapsulated into a user entity object and returned in the list. It is important
1, Entity query:As for the entity query technology, we have already dealt with it many times before, such as the following example:String hql= "from user User";List list=session. CreateQuery (HQL). List ();The result of the above code execution is that all data corresponding to the user entity object is queried, and the data is encapsulated into a user entity object and returned in the list. It is important
1. Object Query:The object query technology has already been involved many times before, for example, the following example:String hql = "from user ";List list = session. createquery (hql). List ();The code above is executed to query all the data corresponding to the user object, encapsulate the data into the user object, and put it in the list to return. It should be noted that there is a judgment on the i
First, use expression to generate query conditions using dynamic expressions,
Expression body = expression. Constant (true );
Body = expression. And (body, expression );
Then execute the query
Session. queryover
The following error is reported:
You cannot forcibly convert objects of the type "nhibloud. hql. Ast. hqlbitwiseand" to the type "nhibloud. hql. Ast. hqlbooleanexpression"
Solution:
Replace express
First, let's take a look at several retrieval methods provided by hibernate:
1. navigation object graph Retrieval Method: navigate to other objects based on the loaded objects. For example, for a loaded customer object, call its getorders (). the iterator () method can be used to navigate to all associated order objects. If a delayed loading search policy is used at the association level, hibernate loads the associated order object from the database. Otherwise, it retrieves the order object from
(UUID) from Teachermodel "The result returned by the Lcount function must be received with the Long dataOther functions are selected based on the data type of the operation, for example, the age in the previous example needs to be received using an integer typehql--Paging QueryLHQL the paging in the query is no longer done manually by the user, you can use the method provided by the query object to complete? setfirstresult (int);? setmaxresults (int);L The above two method return values are the
object is persisted or in a free State, and can easily navigate from one object to the object associated with it. 2. An outer join is used, and the number of SELECT statements is small.Cons: You may load objects that your application does not need to access, wasting a lot of memory space. 2. Complex database table joins can also affect retrieval performance.batch-size Properties:Whether immediate or deferred retrieval, you can specify the number of a
style, and its set method returns its own instance instead of the void type. The method chain programming style can make the program code more concise.Example code:
Query query = session.createquery ("from Customer as C where" +"C.name=:customername and C.age=:customerage");
Dynamic binding Parameters
Query.setstring ("CustomerName", "Test");
Query.setinteger ("Customerage", 21);
Perform a search
List result = Query.list ();
Method Chain Programming Style
List result1 = Ses
join similar to the same, will be converted to "." The queried data is saved to the list object, which can be used to get the contents of the query through list.second, external named queryAn external named query refers to writing a query statement into a mapping file, using 2.1 External Query Statements The following example demonstrates the application of an external query statement, adds a The external named query put the query into the mapping
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.