2015-10-06 33 views
1

當我直接通過sql在postgesql上執行該語句時,它起作用。SQL查詢確定,但使用Hibernate「查詢返回了多個ResultSet」。 - 錯誤

當使用java服務/ hibernate時,它返回錯誤「查詢返回多個ResultSets」。

在eclipse中設置hibernate的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; 
} 
+0

也許它聽起來很愚蠢,但你有沒有嘗試在查詢結束時刪除分號,就像'sql.append(「month asc」);'? – Filip

回答

1

通常,查詢結尾的分號是原因。檢查this了。另一個原因可能是多個選項存在於同一個查詢中,如this other SO post中所述。

+0

謝謝安德烈, 我認爲這個原因肯定是hibernate/postgresql的更新,因爲它幾個星期前就在工作。 –