SQLQuery Implementing alias Mappings

Source: Internet
Author: User

 PublicList getquerylist (Map parammap,intStartintMaxResults)throwsDataAccessException, Hibernateexception, Instantiationexception, Illegalaccessexception, InvocationTargetE Xception, nosuchmethodexception {String Wono= ""; String Wosubject= ""; Date Creationdatefrom=NULL; Date Creationdateend=NULL; if(Parammap.get ("Wono")! =NULL) {Wono= (String) parammap.get ("Wono");        }        ; if(Parammap.get ("Wosubject")! =NULL) {Wosubject= (String) parammap.get ("Wosubject"); }        if(Parammap.get ("Creationdatefrom")! =NULL) {Creationdatefrom= (Date) parammap.get ("Creationdatefrom"); }        if(Parammap.get ("Creationdateend")! =NULL) {Creationdateend= (Date) parammap.get ("Creationdateend"); } stringbuffer buf=NewStringBuffer (); Buf.append ("Select Abh.*,"); Buf.append ("Fw.wo_no Bill_code,"); Buf.append ("Fw.wo_type Bill_type,"); Buf.append ("Fw.wo_subject Bill_title,"); Buf.append ("Fw.created_date creation_date,"); Buf.append ("Fw.process_instance_id process_instance_id,"); Buf.append ("' transated ' Task_type,"); Buf.append ("(select Au.user_name from Arch_user au where au.user_id=abh.created_by) created_name,"); Buf.append ("(select Ao.org_name from arch_org ao where ao.org_id=abh.arch_org_company_id) region_company_segment,"); Buf.append ("(select Ao.org_name from arch_org ao where ao.org_id=abh.arch_org_dept_id) region_dept_segment"); Buf.append ("From Fas_workorder FW, Account_bill_head ABH where 1 = 1"); Buf.append ("And Fw.businessid = abh.account_bill_head_id"); Buf.append ("And Fw.wo_no Like:wono"); Buf.append ("And Fw.wo_subject Like:wosubject"); Buf.append ("And Fw.created_date between NVL (: Creationdatefrom,fw.created_date) and NVL (: creationdateend,sysdate)"); Buf.append ("ORDER BY fw.created_date Desc"); List beanlist=NULL; Session Session=NULL; Try{Session=accountbillheaddao.gethibernatetemplate (). Getsessionfactory (). Opensession (); //get local SQL query ObjectSQLQuery query =Session.createsqlquery (buf.tostring ()); //Setting String ParametersQuery.setstring ("Wono", "%" + Wono + "%"); Query.setstring ("Wosubject", "%" + wosubject + "%"); //Set Date ParametersQuery.setdate ("Creationdatefrom", Creationdatefrom); Query.setdate ("Creationdateend", Creationdateend); //Set Page PagingQuery.setfirstresult (start);            Query.setmaxresults (MaxResults); Query.setresulttransformer (NewExtcolumntobean (Accountbillheadvoimpl.class)); Beanlist=query.list (); } Catch(RuntimeException e) {//TODO auto-generated Catch blockE.printstacktrace (); } finally{Session.flush ();        Session.close (); }        returnbeanlist; }

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.