Go to: Hibernate query method

Source: Internet
Author: User
1: QBE (query by example)

Criteria CRI = session. createcriteria (student. Class); CRI. Add (example. Create (s); // s is a student object listcri. List ();

Essence: Create a template. For example, I have a table serial with a giftortoy field. I set serial. setgifttoy ("2 "),

All the giftortoy Data in this table is returned.

  2: QBC (query bycriteria) mainly consists of criteria, criterion, Oder, restrictions class

 
Session = This. getsession (); Criteria
CRI = session. createcriteria (jditemserialnumber. Class); Criterion
Cron = restrictions. Like ("customer", name); CRI. Add (cron); List = CRI. List ();

Comparison Operators

Hql operator QBC operator meaning

= Restrictions. eq () equals

<> Restrictions. Not (exprission. eq () is not equal

> Restrictions. gt () is greater

> = Restrictions. Ge () is greater than or equal

<= Restrictions. Le () is less than or equal

Is null restrictions. isnull () is null

Is not nullrestrictions. isnotnull () non-null

Like restrictions. Like () string mode matching

And restrictions. And () logic and

And restrictions. conjunction () logic and

Or restrictions. Or () logic or

Or restrictions. disjunction () logic or

Notrestrictions. Not () logical non-

In (list) restrictions. In () is equal to a value in the list.

ONT in (list) restrictions. Not (restrictions. In () is not equal to any value in the list

Any value in between x and yrestrictions. Between () closed range XY

Not between x and yrestrictions. Not (restrictions... between () is smaller than the value x or greater than the value Y

  3: hql

 
String hql = "select S. Name, AVG (S. Age) from student s
Groupbys. Name "; query =
Session. createquery (hql); List = query. List ();....

  4: Local SQL query

  5: qid

The get () and load () Methods of the session provide the way to retrieve Objects Based on the Object ID. This method is used to know the ID of the object to be retrieved in advance.

Edit recommendations

Layer-by-layer parsing of abuse of transactions in hibernate

Questions about STRUTS + hibernate Paging

Perfect Combination of struts and Hibernate

Six things you must know about hibernate

Related Article

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.