關於hibernate子查詢參數的問題

來源:互聯網
上載者:User

標籤:

private Map<String, Object> createWblHqlContext(boolean needGroup, String startDate, String endDate) {
        Map<String, Object> context = new HashMap<String, Object>();
        // 構建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;
    }

    // 構造select欄位
    private String createVaInfoWblDaySelectPart(String startDate,String endDate) {
        StringBuilder sb = new StringBuilder();
        sb.append("select t.settlementDate,");// 清算日期
        sb.append("sum(t.amount)/100 ,"); // 清算交易金額
        sb.append("sum(t.amount)/100 ,"); // 交易筆數
        sb.append("sum(t.shopfee)/100 ,"); // 商戶手續約
        sb.append("((sum(t.sdsy)/100-sum(t.advancefee)/100)) ,"); // 王府井入賬金額
        sb.append("sum(t.sdsy)/100, "); // 收單收入
        sb.append("sum(t.wangsy)/100,"); // 王府井收入
        sb.append("sum(t.cjfsy)/100, "); // 外掛程式方收入
        sb.append("sum(t.wangsh)/100, "); // 王府井損失
        sb.append("sum(t.cjfsh)/100 "); // 外掛程式方損失
        sb.append("( ").append(this.createNoCardPayQueryThirdsySelectByPart())
        .append(this.createNoCardPayQueryThirdsyFromByPart(startDate, endDate))
        .append(" and t.mernum = ‘898110248990216‘").append(this.createVaInfoWblDayGroupByPart()).append(") ");//代墊手續約(國美)
        

        return sb.toString();
    }

    // 構造group by欄位
    private String createVaInfoWblDayGroupByPart() {
        StringBuilder sb = new StringBuilder();
        sb.append("group by t.settlementDate ");
        return sb.toString();
    }
    
    //構造sql查詢代墊手續約,
    private String createNoCardPayQueryThirdsySelectByPart() {
        StringBuilder sb = new StringBuilder();
        sb.append("select sum(t.thirdsy)/100 ");
        return sb.toString();
    }

    //構造sql查詢代墊手續約的from部分
    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();
    }

當添加紅色部分內容時,頁面就報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.settlementDate >= ? and t.settlementDate <= ? group by t.settlementDate

求助!!!

關於hibernate子查詢參數的問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.