【发布时间】:2015-10-06 07:55:59
【问题描述】:
当我在 postgesql 上直接通过 sql 执行语句时,它可以工作。
使用 java 服务/休眠时,它返回错误“查询返回了多个结果集。”
在 Eclipse 中为休眠设置 max.log 不会显示更多细节。
有人遇到过这个问题并找到了解决方案吗?提前致谢。
public List<List<String>> getProductionGroupedByTime(
final Object[] policyTypes,
final Object[] policyStatuses,
final Object[] businessTypes,
final Object[] businessChannels,
final Object[] agents,
final Object[] agents2,
final Object[] roles,
final Object[] productDetails,
final Date beginDate,
final Date endDate) {
final long begin = System.currentTimeMillis();
final Session session = sessionFactory.getCurrentSession();
final StringBuffer sql = new StringBuffer();
sql.append("select ");
sql.append("cast(extract(year from coalesce(p.production_date,p.date_created)) as text) as year, ");
sql.append("cast(extract(month from coalesce(p.production_date,p.date_created)) as text) as month, ");
sql.append("cast(count(p.id) as text) as count, ");
if (ArrayUtils.isNotEmpty(productDetails)) {
sql.append("cast(sum(ipd.premium) as text) as prod, ");
} else {
sql.append("cast(sum(coalesce(p.manual_premium,p.premium)) as text) as prod, ");
}
sql.append("cast(round((sum(coalesce(p.manual_premium,p.premium)) / 100 ) + count(p.id), 2) as text) as points ");
sql.append("from policy p ");
sql.append(addJoinsAndWhereClause(policyTypes, policyStatuses, businessTypes, businessChannels, agents, agents2, roles, productDetails, beginDate, endDate));
sql.append("group by ");
sql.append("year, ");
sql.append("month ");
sql.append("having sum(coalesce(p.manual_premium,p.premium)) > 0 ");
sql.append("order by ");
sql.append("year asc, ");
sql.append("month asc; ");
logger.debug(sql);
SQLQuery query = session.createSQLQuery(sql.toString());
query = setQueryParameters(query, policyTypes, policyStatuses, businessTypes, businessChannels, agents, agents2, roles, productDetails, beginDate, endDate);
final List<List<String>> result = DiacUtils.listOfObjectArrayToListOfListOfString(query.list());
logger.debug((System.currentTimeMillis() - begin) + " ms");
return result;
}
【问题讨论】:
-
也许听起来很傻,但您是否尝试过删除查询末尾的分号,例如
sql.append("month asc");?
标签: java eclipse hibernate postgresql