2014-02-19 62 views
3

我有以下查詢:在休眠「情況下......然後......其他......結束」時可以使用「和」?

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 
+1

你的意思是字符串連接(即姓+名)還是邏輯AND? –

+0

@PeterBratton,我的意思是串聯,但順便說一句,有可能使用邏輯AND? – Dragon

回答

2

既然你選,我相信你的意思來連接姓名:

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

HQL Query Expressions在文檔中的更多細節。

+1

我的意思是連接,抱歉不正確的解釋和感謝您的幫助,這個解決方案很大。 – Dragon

相關問題