简体   繁体   中英

It is possible to use “and” in hibernate “case when…then…else…end”?

I have the following query:

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;

It works correctly. But I need not only clientReq.name but also clientReq.surname . Is it possible to combine theese two columns in this case when...then...else...end ?

Something like:

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

This one throws exception:

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

Since you're sorting, I presume you mean to concatenate name and surname:

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

See HQL Query Expressions in the docs for more details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM