2012-09-10 80 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