无法从Hibernate Native Query中的结果集中读取列值

时间:2016-06-11 11:04:29

标签: java mysql hibernate

 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-console中正常运行,但是当我与Hibernate集成时,Hibernate会抛出以下错误。

[BigIntegerType]无法从结果集中读取列值:ID;未找到列“ID”。

1 个答案:

答案 0 :(得分: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而不是ClientID返回。 因此,尝试在没有别名的情况下运行查询,通常,JDBC中存在此问题。如果您仍然坚持使用别名,请将以下条目添加到配置文件

中的JDBC URL

[useOldAliasMetadataBehavior = true]