0

如何用休眠查询语言编写此查询

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

4

1 回答 1

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";
于 2012-09-10T01:34:23.673 回答