亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

hibernate hql sum case when else end execution in

hibernate hql sum case when else end execution in

江戶川亂折騰 2021-09-12 19:48:38
我需要HQL query在Java中執行with sum when else end 子句,該子句在以下環境中運行沒有問題postgres:SELECT r.reviewer_id,  sum(case when c.service_type = '????? ????' AND c.genre_id = '66c92962-324c-11e7-93ae-92361f002671' then 1 else 0 end) image_multimedia,  sum(case when c.service_type is null AND c.genre_id = '66c92b1a-324c-11e7-93ae-92361f002671' then 1 else 0 end) image_null FROM module_samim.content c  Join module_samim.content_reviewer r on c.id = r.content_id  Join module_samim.file f on f.id = c.file_id  Group by r.reviewer_id我試圖運行它,createQuery()但我得到:Sep 11, 2018 8:57:20 AM org.hibernate.hql.internal.ast.ErrorCounter reportErrorERROR: line 1:58: expecting "then", found '????AND'line 1:58: expecting "then", found '????AND'andSep 11, 2018 8:57:20 AM org.hibernate.hql.internal.ast.ErrorCounter reportErrorERROR: line 1:264: unexpected token: image_nullSep 11, 2018 8:57:20 AM org.hibernate.hql.internal.ast.ErrorCounter reportErrorERROR: line 1:264: unexpected token: image_nullline 1:264: unexpected token: image_null請幫我!謝謝你!
查看完整描述

3 回答

?
炎炎設計

TA貢獻1808條經驗 獲得超4個贊

語法似乎是 SQL,而不是 HQL。

因此,我們需要代替這個

createQuery()

稱之為

createSqlQuery()


查看完整回答
反對 回復 2021-09-12
?
郎朗坤

TA貢獻1921條經驗 獲得超9個贊

我找到了解決方案:)) 我使用createNativeQuery()并在此鏈接中解釋了@SqlResultSetMapping以完全解決我的問題


查看完整回答
反對 回復 2021-09-12
?
拉風的咖菲貓

TA貢獻1995條經驗 獲得超2個贊

您似乎在 HQL/JPQL createQuery API 上混合使用本機查詢


為了給你澄清一下,我們可以通過三種不同的方式在 Hibernate 中創建 SQL 查詢:


   1) session.createQuery()             //Hibernate APi

   2) entityManager.createQuery()       //JPA Api


   3) session.createSQLQuery()          // **** Hibernate API ****

   4) entityManager.createNativeQuery() //JPA API

因此,如果您使用 Hibernate,您應該使用 session.createSQLQuery(),如果您使用 JPA,您應該使用 entityManager.createNativeQuery()


查看完整回答
反對 回復 2021-09-12
  • 3 回答
  • 0 關注
  • 189 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號