簡體   English   中英

這個HQL有什么問題? 丟失的逗號在哪里?

[英]What's wrong with this HQL? Where is the missing comma?

我得到了這個hibernate異常:

 org.hibernate.QueryException: , expected in SELECT [select tc.id as
 id, tc.terminalServerPort.id as terminalServerPortId,
 tc.terminalServerPort.terminalServer.name as terminalServerName,
 tc.terminalServerPort.terminalServer.ipConfig.ipAddress as
 terminalServerIpAddress, tc.terminalServerPort.portNumber as
 terminalServerPort from
 com.windriver.dsm.labmanagement.data.TargetConsole tc where
 tc.target.id = :targetId order by id asc]

有任何想法嗎? 謝謝!

Even when I narrow the HQL to the minimum I still get that exception - , expected in SELECT [select tc.id as id from com.windriver.dsm.labmanagement.data.TargetConsole as tc]

你不應該這樣寫嗎?

[select tc.id as id from com.windriver.dsm.labmanagement.data.TargetConsole tc]

為什么你寫as給別名表的時候?

我找到了解決方案。

顯然我正在使用的hibernate版本(hibernate 3) 不允許為關聯實體分配別名 當我刪除這些別名 - 查詢工作。

這是正確的代碼:

select tc.id, tc.terminalServerPort.id, 
tc.terminalServerPort.terminalServer.name, 
tc.terminalServerPort.terminalServer.IPConfig.IPAddress, 
tc.terminalServerPort.portNumber 
from TargetConsole tc where tc.target.id = :targetId order by id asc

謝謝你的幫助!

您需要為正在使用的sessionFactory配置hibernate轉換程序屬性。

hibernate.query.factory_class = org.hibernate.hql.ast.ASTQueryTranslatorFactory

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM