简体   繁体   English

这个HQL有什么问题? 丢失的逗号在哪里?

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

I'm getting this hibernate exception: 我得到了这个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]

Any ideas? 有任何想法吗? Thanks! 谢谢!

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]

Shouldn't you write it this way? 你不应该这样写吗?

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

Why are you writing as when giving alias to table? 为什么你写as给别名表的时候?

I found the solution. 我找到了解决方案。

Apparently the hibernate version which I'm using (hibernate 3) does not allow assigning aliases to associated entities . 显然我正在使用的hibernate版本(hibernate 3) 不允许为关联实体分配别名 When I remove those aliases - the query works. 当我删除这些别名 - 查询工作。

Here is the correct code: 这是正确的代码:

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

Thanks for the help guys! 谢谢你的帮助!

您需要为正在使用的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