关于hibernate子查询参数的问题
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
求助!!!
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。