An example of hql Query

Source: Internet
Author: User

 

Because the hql statement needs to query a string-type prefix, the type returned after the hql statement is queried is list <string>. If you want to query two or more fields, the return type is list <object []>. Then, traverse the list set and convert the corresponding fields to the corresponding type.

Public list <string> findbyhql (string provincename, string regionname, string yys) throws baseexception {try {stringbuffer hql = new stringbuffer (); hql. append ("select ps. prefix from phonesegment PS where Ps. province. name = "+" '"+ provincename +"' "); If (stringutils. isnotblank (regionname) {hql. append ("and PS. region. name = "+" '"+ regionname +"' ");} If (stringutils. isnotblank (yys) {string [] STRs = yys. split (","); string phonetypes = ""; for (INT I = 0; I <STRs. length; I ++) {phonetypes + = enum. valueof (phonetype. class, STRs [I]). ordinal () + ",";} phonetypes = phonetypes. substring (0, phonetypes. length ()-1); hql. append ("and phonetype in (" + phonetypes + ")");} return basedao. find (hql. tostring ();} catch (exception e) {log. error (E. getmessage (), e); throw new baseexception (e );}}

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.