HQL query based on Pojo class construction method

Source: Internet
Author: User

There are many ways to query hql, and yesterday came into contact with a query method based on the Pojo class, summarized here:

Usually we can use simple "from [POJO OBJ]" syntax to assemble a simple hql query. If we want to specify a field, we can use the syntax of the new Pojo object, as follows:


The following article uses Weiboaccountbean to refer to Pojo objects:

Select new                 Weiboaccountbean (Bean.accountid,bean.expire,bean.token,bean.companyid,bean.userid, Bean.accountemail,bean.accountname,bean.accountpassword,bean.status,bean.openurl,bean.isenable,bean.source) From  Weiboaccountbean Bean where 1=1



The HQL can use the query object produced by the Session.createquery method to execute the list method, as follows:

Query query = This.gethibernatetemplate (). Getsessionfactory (). Getcurrentsession (). CreateQuery (HQL); 
Query.list ();


The Pojo class must be combined with the following construction methods:

    Public    Weiboaccountbean (Integer   accountid,string   expire,string  token,integer  CompanyID, String   userid,string  accountemail,string  accountname,string  accountpassword,integer   status,string openurl,string isenable,string source) {
    	  this.accountid=accountid;
    	  This.expire=expire;
    	  This.token=token;
    	  This.companyid=companyid;
    	  This.userid=userid;
    	  This.accountemail=accountemail;
    	  This.accountname=accountname;
    	  This.accountpassword=accountpassword;
    	  This.status=status;
    	  This.openurl = OPENURL;
    	  this.isenable = isenable;
    	  This.source = source;
      }


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.