我得到了这个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]
有什么想法吗? 谢谢!
答案 0 :(得分:1)
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
?
答案 1 :(得分:1)
我找到了解决方案。
显然我正在使用的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
感谢帮助人员!
答案 2 :(得分:1)
您需要为正在使用的sessionFactory配置hibernate转换程序属性。
hibernate.query.factory_class = org.hibernate.hql.ast.ASTQueryTranslatorFactory