2013-10-10 90 views
1
from (From FlightSchedule as a where a.route.routeId=1) as b 

上述查询有什么问题? 它给我这个错误Hibernate查询语法错误?

org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: (near line 1, column 6 [from 
(From FlightSchedule as a where a.route.routeId=1) as b] 

我试图写它以不同的方式,但不工作。 我认为内部查询应该评估一个对象列表,并且第一个from令牌应该返回相同的值。 请告诉我我做错了什么? 谢谢。

+0

您的整个查询是怎样的?将From改为From,它们区分大小写。 – Zeus

+0

IN mysql这应该是这样的: select * from(select * from FlightSchedule where routeId = 1)a; –

+0

为什么在这里使用嵌套查询?顺便说一句,如果你想要嵌套查询,嵌套查询应包含'select'子句,并且据我所知你不能在hibernate的'from'子句中使用嵌套查询。 –

回答

3

你的假设是错误的。这是无效的HQL。引用自the documentation

请注意,HQL子查询只能出现在select或where子句中。

+0

谢谢您的回答。但我该如何编写HQL等效于 select * from(select * from FlightSchedule where routeId = 1)a; –

+0

HQL有选择语法,它将成为select * from(from ....)b – Zeus

+0

我也试过,但现在它说的是意外的标记*。 另外,我没有在文档页面上找到任何select *示例。 –