Hibernate使用Native SQL报Column not found 博客分类: Java
Map<String, Object> params = new HashMap<String, Object>();
params.put("startDate", startDate);
params.put("endDate", endDate);
StringBuilder sql = new StringBuilder();
sql.append("SELECT s.id as {ss.id}, ");
sql.append("s.report_date as {ss.reportDate},");
sql.append("SUM(s.new_today_count) as {ss.newTodayCount},");
sql.append("SUM(s.new_last_seven_days_count) as {ss.newLastSevenDaysCount},");
sql.append("SUM(s.new_last_thirty_days_count) as {ss.newLastThirtyDaysCount},");
sql.append("SUM(s.total_count) as {ss.totalCount}, ");
sql.append("s.created_date as {ss.createdDate} ");
sql.append("FROM stat_hq_store_daily s ");
sql.append("where s.report_date BETWEEN :startDate AND :endDate ");
if (provinceId > 0) {
sql.append("AND province_id = :provinceId ");
params.put("provinceId", provinceId);
}
if (cityId > 0) {
sql.append("AND city_id = :cityId ");
params.put("cityId", cityId);
}
if (districtId > 0) {
sql.append("AND district_id = :districtId ");
params.put("districtId", districtId);
}
sql.append("GROUP BY s.report_date");
Map<String, Class> classes = new HashMap<String, Class>();
classes.put("ss", StatHqStoreDaily.class);
return (List<StatHqStoreDaily>)sqlQuery(sql.toString(), params, classes);
OR