org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: limit nea
时间:2021-12-14 作者:匿名
域名.域名ySyntaxException: unexpected token: limit near line 1, column 80 [ SELECT name FROM cla_hospital WHERE city=\'北京市\' and name like \'%北京%\' limit 8 ] at 域名.域名域名ert(域名:91) at 域名.域名域名wQueryException(域名:109) at 域名.域名域名e(域名:304) at 域名.域名域名mpile(域名:203) at 域名.域名域名ile(域名:158) at 域名域名.HQLQueryPlan.<init>(域名:126) at 域名域名.HQLQueryPlan.<init>(域名:88)
但上面的sql语句直接拿到数据库是对的 。。
原因
SELECT name FROM cla_hospital WHERE city=\'北京市\' and name like \'%北京%\' limit 8
你这句话是标准的sql语句,但是你在这里域名urrentSession().createQuery(sql);开启的是hibernate的面向对象的语句所以不可以,你改成域名urrentSession().createSQLQuery(sql);就可以了