SQL Query OK, but using Hibernate "Multiple ResultSets were returned by the query."-Error

when I execute the statement directly via sql on postgesql it works.

When using java service / hibernate, it returns me the error “Multiple ResultSets were returned by the query.”

Setting max.log for hibernate in eclipse doesn’t show more details.

Does anybody had this and found an solution? Thanks in advance.

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;
}


Source: eclipse

Leave a Reply