Questions about Hibernate sub-query parameters

Source: Internet
Author: User

Private map<string, Object> createwblhqlcontext (Boolean needgroup, String StartDate, String endDate) {
Map<string, object> context = new hashmap<string, object> ();
Build HQL
StringBuilder hql = new StringBuilder ();
Hql.append (This.createvainfowbldayselectpart (StartDate, EndDate)). Append ("");

Hql.append ("from WFJWBL t where 1=1");
list<object> params = new arraylist<object> ();
if (startdate.length () > 0) {
Hql.append ("and T.settlementdate >=?");
Params.add (StartDate);
}
if (enddate.length () > 0) {
Hql.append ("and T.settlementdate <=?");
Params.add (endDate);
}
if (Needgroup)
Hql.append (""). Append (This.createvainfowbldaygroupbypart ());
Context.put ("Hql", hql.tostring ());
Context.put ("params", params);
return context;
}

Construct the Select field
private string Createvainfowbldayselectpart (String startdate,string endDate) {
StringBuilder sb = new StringBuilder ();
Sb.append ("Select T.settlementdate,");//Liquidation Date
Sb.append ("sum (t.amount)/100,"); Liquidation Transaction Amount
Sb.append ("sum (t.amount)/100,"); Number of trading Pens
Sb.append ("sum (t.shopfee)/100,"); Merchant Handling Fee
Sb.append ("((Sum (t.sdsy)/100-sum (t.advancefee)/100),"); Wangfujing Amount
Sb.append ("sum (t.sdsy)/100,"); Income from receipt of orders
Sb.append ("sum (T.wangsy)/100,"); Wangfujing Revenue
Sb.append ("sum (t.cjfsy)/100,"); Plug-in party revenue
Sb.append ("sum (T.WANGSH)/100,"); Wangfujing loss
Sb.append ("sum (T.CJFSH)/100"); Plugin-side loss
sb.append ("("). Append (This.createnocardpayquerythirdsyselectbypart ())
. Append (This.createnocardpayquerythirdsyfrombypart (StartDate, endDate))
. Append ("and t.mernum = ' 898110248990216 '"). Append (This.createvainfowbldaygroupbypart ()). Append (")");//Mat handling fee (Gome)


return sb.tostring ();
}

Constructing a GROUP By field
Private String Createvainfowbldaygroupbypart () {
StringBuilder sb = new StringBuilder ();
Sb.append ("GROUP by T.settlementdate");
return sb.tostring ();
}

Construct SQL query mat handling fee,
Private String Createnocardpayquerythirdsyselectbypart () {
StringBuilder sb = new StringBuilder ();
Sb.append ("Select SUM (t.thirdsy)/100");
return sb.tostring ();
}

Construct the from section of the SQL query mat handling fee
private string Createnocardpayquerythirdsyfrombypart (string startdate, String endDate) {
StringBuilder sb = new StringBuilder ();
Sb.append ("from WFJWBL t where 1=1");
list<object> params = new arraylist<object> ();
if (startdate.length () > 0) {
Sb.append ("and T.settlementdate >=?");
Params.add (StartDate);
}
if (enddate.length () > 0) {
Sb.append ("and T.settlementdate <=?");
Params.add (endDate);
}
return sb.tostring ();
}

When adding a red section, the page is quoted as org.springframework.orm.hibernate3.HibernateQueryException:unexpected token: (Near Line 1, Column 215 [select T.settlementdate,sum (t.amount)/100, sum (t.amount)/100, sum (t.shopfee)/100, ((SUM (t.sdsy)/100-sum ( T.advancefee)/100), sum (t.sdsy)/100, sum (T.wangsy)/100,sum (t.cjfsy)/100, sum (T.WANGSH)/100, sum (T.CJFSH)/100 ( Select SUM (t.thirdsy)/100 from Cn.net.wangfujing.model.WfjWbl t where 1=1 and T.settlementdate >=? and T.settlementdate <=? and t.mernum = ' 898110248990216 ' GROUP by t.settlementdate) from Cn.net.wangfujing.model.WfjWbl t where 1=1 and T.settleme Ntdate >=? and T.settlementdate <=? GROUP BY T.settlementdate

Help!!!

Questions about Hibernate sub-query parameters

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.