我需要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貢獻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()
添加回答
舉報
0/150
提交
取消