2014-04-04 27 views
0

我從我的java類運行這個hibernate查詢。但我得到QuerySyntaxException.But我沒有發現任何事情出錯了。HibQuerySyntaxException當我在查詢中使用CAST()

查詢

SELECT count(contact.id) 
FROM Contact contact 
WHERE contact.id IN (
    SELECT DISTINCT action.contact 
    FROM Action action 
    WHERE action.status = 'O' 
    AND action.currentAssignee = :currentAssignee) 
AND contact.contactStatus IN :contactStatus 
AND CAST(contact.id as char(12)) like :id   --Note this line 
AND contact.issue.productGroup IN :productGroup 

但問題是使用CAST。

的錯誤是

期待CLOSE,發現 '('
錯誤儘管取得countOpenContacts java.lang.IllegalArgumentException異常:org.hibernate.hql.ast.QuerySyntaxException:期待CLOSE,發現「 (」

下面的Java代碼已經被用來設置id(contact.id是長值和的ContactID是字符串。)

query.append("AND CAST(contact.id as char(12)) like :id "); 
params.put("id",(contactId+ "%")); 

我們可以在休眠查詢中投入嗎?

回答

1

由於documentation說,我們可以使用

cast(... as ...), where the second argument is the name of a Hibernate type 

所以,你應該嘗試

AND CAST(contact.id as string) like :id 
+0

許多許多thanks.Thats很大help.Thank你了尤金。 –

相關問題