java - hibernate hql sum case when then else end execution in java 问题

标签 java sql hibernate hql createquery

我需要在 Java 中执行一个带有 sum when then else end 子句的 HQL 查询,它在 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 reportError
ERROR: line 1:58: expecting "then", found 'مدیاAND'
line 1:58: expecting "then", found 'مدیاAND'
and

Sep 11, 2018 8:57:20 AM org.hibernate.hql.internal.ast.ErrorCounter reportError
ERROR: line 1:264: unexpected token: image_null
Sep 11, 2018 8:57:20 AM org.hibernate.hql.internal.ast.ErrorCounter reportError
ERROR: line 1:264: unexpected token: image_null
line 1:264: unexpected token: image_null

请帮帮我! 谢谢!

最佳答案

语法好像是SQL,不是HQL。

因此,我们需要的不是这个

createQuery()

这样称呼

createSqlQuery()

关于java - hibernate hql sum case when then else end execution in java 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52268705/

相关文章:

java - H2 with MODE=Oracle 导致 'Schema "information_schema"not found'

java - Bean属性dataSource在Spring + Hibernate 3中不可写(因无法添加更多代码而重新发布)

Java BigDecimal from String without decimal places 但 asume 最后两位数字为 decimal

Java接受新数组作为输入,尽管我给出了两次源代码

sql - 从巨大的生产表中复制数据

SQLite3 UNIQUE 约束失败错误

java - java中JLabel圆角的最简单代码

java - 尝试创建 Toast.makeText 时出错

php - 设置 MySQL 字段的最小值 - 可能吗?

java - 从 SQL 查询 Hibernate Java 获取对象