随笔-42  评论-349  文章-4  trackbacks-0

HQL查询语句:from Course course where course.name like '%计算机%' order by course.date desc  异常:

[org.hibernate.hql.PARSER] - <AST>:0:0: unexpected end of subtree 2008-05-06
18:36:04,062 ERROR [org.hibernate.hql.PARSER] -  Invalid path: 'course.name'
2008-05-06 18:36:04,062 ERROR [org.hibernate.hql.PARSER] - <AST>:0:0: unexpected end of subtree
2008-05-06 18:36:04,062 ERROR [org.hibernate.hql.PARSER] -  left-hand operand of a binary operator was null
2008-05-06 18:36:04,093 ERROR [org.hibernate.hql.PARSER] -  Invalid path: 'course.date'
2008-05-06 18:36:04,125 ERROR [com.vod.dao.CourseDAO] - find all failed org.springframework.orm.hibernate3.HibernateQueryException: unexpected end of subtree [where course.name like '%计算机%' order by course.date desc ]; nested exception is org.hibernate.hql.ast.QuerySyntaxException: unexpected end of subtree [where course.name like '%计算机%' order by course.date desc ]Caused by: org.hibernate.hql.ast.QuerySyntaxException: unexpected end of subtree [where course.name like '%计算机%' order by course.date desc ] at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:59) at
org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:225) at
org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:158) at
org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:109) at
org.hibernate.engine.query.HQLQueryPlan.<init>
(HQLQueryPlan.java:75) at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:54) at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:71) at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133) at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112) at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:15……

问题解决了:语句写错了!!:
 1   public List findByHql(String hql){    
 2         log.debug("finding all Course instances");     
 3         try {
 4            String queryString = "from Course course " +hql+" ";
 5            System.out.println("\n\n"+queryString+"\n\n");
 6            return getHibernateTemplate().find(queryString);
 7         } catch (RuntimeException re) {
 8            log.error("find all failed", re);
 9            throw re;
10         } 
11 }

写成了:
 1 public List findByHql(String hql){
 2      log.debug("finding all Course instances");
 3      try {
 4          String queryString = "from Course course " +hql+" ";
 5          System.out.println("\n\n"+queryString+"\n\n");
 6          return getHibernateTemplate().find(hql);//就这里!真是郁闷
 7       } catch (RuntimeException re) {
 8          log.error("find all failed", re);
 9          throw re;
10       } 
11 }




By:残梦追月
posted on 2008-07-09 22:18 残梦追月 阅读(11286) 评论(1)  编辑  收藏 所属分类: Spring

评论:
# re: Hibernate unexpected end of subtree异常解决办法 2012-12-29 12:56 | hql是什么
hql是什么,这个问题就这么解决了?  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航: