2016-06-11 57 views
0
SELECT 
    CONCAT(CREG.FIRSTNAME, ' ', CREG.LASTNAME) AS NAME, 
    CASE WHEN CR.CAMPAIGNTYPE = 'NPS' 
    THEN NPSSCORE 
    ELSE CSATSCORE END       AS SCORE, 
    IFNULL(cast(CC.TEXT AS CHAR(255)), '')  AS COMMENTS, 
    CREG.ID         AS CLIENTID, 
    CR.ID          AS CAMPAIGNRESPONSEID, 
    CI.ID          AS ISSUEID 
FROM CUSTOMER_ISSUES CI INNER JOIN (SELECT DISTINCT ISSUEID 
            FROM ISSUE_DEPARTMENT_MAPPING 
            WHERE CUSTOMERUSERID = 91 AND ISSUE_STATUS = 'New') IDM 
    ON CAST(CI.FEEDBACK_DATE AS DATE) BETWEEN '2016-06-05' AND '2016-06-11' AND IDM.ISSUEID = CI.ID 
    INNER JOIN CAMPAIGN_RESPONSE CR ON CR.ID = CI.CAMPAIGN_RESPONSE_ID 
    INNER JOIN CLIENT_REGISTRATION CREG ON CREG.ID = CR.RESPONSECUSTOMERID 
    LEFT OUTER JOIN CAMPAIGN_COMMENTS CC ON CC.CAMPAIGN_RESPONSE_ID = CR.ID; 

上述查詢正常運行在mysql控制檯中,但是當我與Hibernate集成時,Hibernate會引發以下錯誤。無法從休眠狀態的結果集中讀取列值Native Query

[BigIntegerType]無法從結果集中讀取列值:ID;未找到列'ID'。

+0

集'show_sql = TRUE'獲得印刷日誌/控制檯上的SQL,檢查它是否運行良好在mysql-console中。你如何綁定參數?還發布完整的堆棧跟蹤 – Saravana

回答

1

嘗試刪除SQL查詢中的別名。

基本上當你運行

SELECT 
    CONCAT(CREG.FIRSTNAME, ' ', CREG.LASTNAME) AS NAME, 
    CASE WHEN CR.CAMPAIGNTYPE = 'NPS' 
    THEN NPSSCORE 
    ELSE CSATSCORE END       AS SCORE, 
    IFNULL(cast(CC.TEXT AS CHAR(255)), '')  AS COMMENTS, 
    CREG.ID         AS CLIENTID, 
    CR.ID          AS CAMPAIGNRESPONSEID, 
    CI.ID          AS ISSUEID 

在JDBC它返回的列CREG.ID,而不是客戶端ID這裏所發生的。 因此,請嘗試在沒有別名的情況下運行查詢,通常,JDBC中有這個問題。如果你仍然堅持使用別名,添加以下條目添加到JDBC URL配置文件

[useOldAliasMetadataBehavior =真]

+0

從所有ID列中刪除別名後,它工作! –