HQL statement writing in Hibernate

Source: Internet
Author: User

 

At the beginning, the HQL statement in the project was relatively casual, and later I checked the Query and


Use the name parameter; colon + field name (or alias); equals to the original "? "Name;
String hql = "from User as user where user. name =: name ";
//....
Query. setString ("name", name); // The first parameter must be named the same as that in hql;

 

 

= "update LicenceSerialNo set curnum=curnum+1 where curareaid=:organId and areaid=:perType"="organId""perType" i=(i<1) ="from LicenceSerialNo  where curareaid=:organId and areaid=:perType"="organId""perType"=(LicenceSerialNo) findQr.list().get(0=licSerial.getLicencetype()+ DecimalFormat("0000"

 
There are many set methods for query, so you don't need to remember them. You can query them when you use them, and master the distinctive methods, for example,
Query. setfirstResult (0); // you can specify the start position of a query.

Query. setMaxResult (10); // you can specify the number of query records.

The most common query Method

Query. list () query. uniqueResult () set series

 

 

Use criterial:

Cr. add () join query restrictions after SQL statements

The Restrictions class provides a query restriction mechanism. It provides many methods to implement query restrictions.

Criteria cr = session.createCriteria(Student.); cr.add(Restrictions.eq("name", "Bill"));List list == (Student)list.get(0

 

 

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.