QuerySyntaxException异常一般都是由HQL语句的语法错误引起,今日在项目开发中遇到一则,记录一下。
异常信息如下:
2011-05-24 17:13:15,843 [pool-4-thread-3] ERROR [cn.com.supertv.srm.SetupMessageHandler] – unexpected token: and near line 1, column 55 [from cn.com.darkmi.entity.sm.ActivitySession s where and s.smartCardId=? and s.state=?]
org.hibernate.hql.ast.QuerySyntaxException: unexpected token: and near line 1, column 55 [from cn.com.darkmi.entity.sm.ActivitySession s where and s.smartCardId=? and s.state=?]
at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:54)
at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:47)
at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:82)
at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:284)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:182)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
at org.hibernate.engine.query.HQLQueryPlan.
at org.hibernate.engine.query.HQLQueryPlan.
仔细检查出问题的HQL语句就能找到问题所在。
错误的HQL语句:
from ActivitySession s where and s.smartCardId=? and s.state=?
where之后多了一个and,正确的HQL语句:
from ActivitySession s where s.smartCardId=? and s.state=?
引起QuerySyntaxException还可能由于以下原因:
(1)使用了全角空格或者全角的问号;
(2)关键字写错,比如将from写作form之类的错误。
Sorry, the comment form is closed at this time.
No comments yet.