0

how to write this query in hibernate query language

select * from preferred_space p, building b, floor f, space_type st, space s
    where p.user_id=11
    and p.space_id=s.id
    and s.building_id=b.id
    and s.floor_id=f.id
    and s.space_type_id=st.id 
    order by p.id;

If I do it this way it is showing me an error?

 String sql =    "from     PreferredSpace p, Space s, Building b, Floor f, SpaceType st " +
                 "where    p.userId = ? " +
                 "and      p.spaceId = s.id" +
                 "and      s.buildingId = b.id" +
                 "and      s.floorId = f.id" +
                 "and      s.spaceTypeId = st.id" +
                 "order by p.id";

error:

ERROR o.h.hql.internal.ast.ErrorCounter - line 1:242: unexpected token: s
16:18:17.569 [http-bio-8080-exec-24] ERROR o.h.hql.internal.ast.ErrorCounter - line 1:242: unexpected token: s
antlr.NoViableAltException: unexpected token: s

shows the same error for every row that starts with "s." and also for "by".

3
  • 1
    And the error it shows you is? Perhaps something about idand not being a column in Space? The fact that you didn't post the error here says to me you didn't read it. One of the best things you can do for yourself is to start reading messages that come up on the screen. Sometimes they don't make sense, but they'll help, I promise. Commented Sep 10, 2012 at 1:32
  • ERROR o.h.hql.internal.ast.ErrorCounter - line 1:242: unexpected token: s 16:18:17.569 [http-bio-8080-exec-24] ERROR o.h.hql.internal.ast.ErrorCounter - line 1:242: unexpected token: s antlr.NoViableAltException: unexpected token: s Commented Sep 10, 2012 at 1:38
  • it shows the above error Commented Sep 10, 2012 at 1:38

1 Answer 1

2

You need to add spaces:

String sql = "from     PreferredSpace p, Space s, Building b, Floor f, SpaceType st " +
             "where    p.userId = ? " +
             "and      p.spaceId = s.id " +
             "and      s.buildingId = b.id " +
             "and      s.floorId = f.id " +
             "and      s.spaceTypeId = st.id " +
             "order by p.id";
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks you! forgot to check to spaces!

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.