6.4.7: WHERE clause of hql Query

Source: Internet
Author: User

Where clauseFilter the selected results to narrow down the selection range. If you do not name an alias for a persistent instance, you can directly use the attribute name to reference the attribute:

 
From person where name like 'Tom %'

The preceding hql statement has the same effect as the following statement:

 
From person as P where P. name like 'Tom %'

The composite attribute expression enhances the WHERE clause function, for example:

 
From Cat cat where Cat. mate. name like "kit %"

In fact, the underlying layer uses implicit join queries. After hibernate3.2.3, only when cat. when the name attribute references a common component attribute or an independently associated object, you can then use the dot to reference the mate attribute, such as CAT. mate. name; if Cat. mate is a set attribute, which is not supported in Versions later than hibernate3.2.3.

As long as there is no set attribute, the hql statement can use the DoT number to implicitly connect multiple data tables:

 
From Foo foowhere Foo. Bar. Baz. Customer. Address. City like "Guangzhou %"

When the preceding hql statement is executed, the corresponding SQL query statement is generated, which is a query connected to four tables.

Special Property IDIt can be used to indicate the identifier of an object:

 
From cat as catwhere cat. ID = 123 from cat as catwhere cat. mate. ID = 69

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.