1
from (From FlightSchedule as a where a.route.routeId=1) as b

What is wrong in above query? It gives me this error

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]

I have tried to write it in different ways but that don't work. What I suppose is that the inner query should evaluate to a list of objects and the same should be returned by the first from token? Please tell me what I am doing wrong? Thank you.

5
  • How does your whole query look like? change the From to from, they are case sensitive. Commented Oct 10, 2013 at 21:10
  • IN mysql This should be like this: select * from (select * from FlightSchedule where routeId=1) a; Commented Oct 10, 2013 at 21:16
  • Why are using nested queries here? By the way if you want nested queries, the nested query shall contain select clause, and as far as I know you can't use nested queries in from clause in hibernate. Commented Oct 10, 2013 at 21:48
  • Why not just From FlightSchedule as a where a.route.routeId=1? Commented Oct 10, 2013 at 21:48
  • because I am going to do self join. select * from (select * from flightschedule where routeId=1) join (select * from flightschedule where routeId=2) Commented Oct 10, 2013 at 22:02

1 Answer 1

3

Your assumptions are wrong. This is invalid HQL. Quote from the documentation:

Note that HQL subqueries can occur only in the select or where clauses.

Sign up to request clarification or add additional context in comments.

5 Comments

Thank you for your answer.But how can I write HQL equivalent to select * from (select * from FlightSchedule where routeId=1) a;
I tried that too but now it says unexpected token *. Also I don't find any select * example on the documentation page.
You can't. subqueries can occur only in the select or where clauses. Use SQL.
Thank you JB Nizet. But with sql I will not get benefit of hibernate cache.Can I?
Yes, you can. Just as with HQL queries. SQLQuery extends Query, which has a setCacheable() method

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.