org.hibernate.hql.ast.QuerySyntaxException异常解决

发表于: java/j2ee | 作者: | 日期: 2011/5/24 05:05

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.(HQLQueryPlan.java:101)
at org.hibernate.engine.query.HQLQueryPlan.(HQLQueryPlan.java:80)

仔细检查出问题的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之类的错误。

: https://blog.darkmi.com/2011/05/24/1803.html

本文相关评论 - 1条评论都没有呢
Post a comment now » 本文目前不可评论

No comments yet.

Sorry, the comment form is closed at this time.