java - 可以在 hibernate 状态 "and"中使用 "case when...then...else...end"吗?

标签 java hibernate

我有以下查询:

select myentity from TEST as test
left join test.org.parent as parentOrg
left join test.clientRequest as clientReq
where test.customId = 1 and (test.dstatus = 1 or test.cm = true)
order by (case when test.request != '' then test.request else clientReq.name end) asc;

它工作正常。但我不仅需要 clientReq.name,还需要 clientReq.surname。在这个case when...then...else...end 中是否可以合并这两列?

类似于:

order by (case when test.request != '' then test.request else (clientReq.name and clientReq.surname) end) asc;

这个抛出异常:

org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected AST node

最佳答案

既然你在排序,我想你的意思是连接名字和姓氏:

order by (case when test.request != '' then test.request else concat(clientReq.name,clientReq.surname) end) asc;

参见 HQL Query Expressions在文档中获取更多详细信息。

关于java - 可以在 hibernate 状态 "and"中使用 "case when...then...else...end"吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21882466/

相关文章:

java - 创建 clojure 库(jar)以便从 java 调用它

java - 监听MySQL数据库的变化并自动更新前端,无需显式刷新前端

java - org.hibernate.service.UnknownServiceException : Unknown service requested [org. hibernate.ogm.service.impl.OgmConfigurationService]

java - 使用 hibernate 检查数据库重复的优化方法

hibernate - bean 初始化失败;嵌套异常是 org.springframework.beans

java - 将查询结果映射到属性

Java 超出范围

java - Java 中转义双引号 Oracle 准备好的语句

java - 这是什么Jini技术?

java - Android 无法使用 ez-vcard 从 VCARD 获取正确的街道地址