2012-09-10 168 views
0

如果我这样做,这样它显示我的错误如何编写Hibernate查询语言如何将查询转换为hibernate查询语言?

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; 

此查询?

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 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 

显示所有以开始行同样的错误 “S”。也为“by”。

+1

而且它表明你是错误?也许关于'idand'不是'Space'中的一列?你没有在这里发布错误的事实告诉我,你没有阅读它。你可以为自己做的最好的事情之一是开始阅读屏幕上显示的消息。有时他们没有道理,但他们会帮助,我保证。 –

+0

错误ohhql.internal.ast.ErrorCounter - 行1:242:意外标记:s 16:18:17.569 [http-bio-8080-exec-24]错误ohhql.internal.ast.ErrorCounter - 行1: 242:意外标记:s antlr.NoViableAltException:意外标记:s – Newbie

+0

它显示上述错误 – Newbie

回答

2

您需要添加空格:

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"; 
+0

谢谢!忘了检查空格! – Newbie