Exception:hibernate HQL不充分支持 case when语句?
2013-11-21 11:26
495 查看
这两天写代码时又碰到这个问题,放到从前就直接改成用SQL了,但是这次比较特殊,不想浪费时间做太多修改,
在网上搜索了很久,各个方法都试了试,还是没有解决,郁闷
不能再浪费时间了,就索性一咬牙改成了SQL,
mark于此,希望有空时有高人能解决
sql.append("select ts,te.teacherName" +
",case ts.labId when 0 then '无' else (select lb.labName from LabBase lb where lb.labId=ts.labId) end as A4" +
",case ts.collegeCode when '00' then '无' else (select co.collegeName from College co where co.collegeCode=ts.collegeCode) end as A5" +
",te.isLock,te.teacherNumber,ts.labId " +
"from TeaStatistics ts,Teacher te where ts.teacherId=te.teacherId ");
就这样就报错了
ERROR 2012 四月 04 10:39:35,216org.hibernate.hql.PARSER (org.hibernate.hql.ast.ErrorCounter.reportError(ErrorCounter.java:56)) - <AST>:0:0: unexpected AST node: query
ERROR 2012 四月 04 10:39:35,217org.hibernate.hql.PARSER (org.hibernate.hql.ast.ErrorCounter.reportError(ErrorCounter.java:56)) - <AST>:0:0: unexpected AST node: query
org.hibernate.hql.ast.QuerySyntaxException: unexpected AST node: query [select ts,te.teacherName,case ts.labId when 0 then '无' else (select lb.labName from entityAndDAO.LabBase lb where lb.labId=ts.labId) end as A4,case ts.collegeCode when '00' then '无' else
(select co.collegeName from entityAndDAO.College co where co.collegeCode=ts.collegeCode) end as A5,te.isLock,te.teacherNumber,ts.labId from entityAndDAO.TeaStatistics ts,entityAndDAO.Teacher te where ts.teacherId=te.teacherId and ts.termYear ='2011-2012' ]
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.analyze(QueryTranslatorImpl.java:261)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:185)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:94)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1651)
at com.lab.action.TeacherAction.listYear(TeacherAction.java:714)
在网上搜索了很久,各个方法都试了试,还是没有解决,郁闷
不能再浪费时间了,就索性一咬牙改成了SQL,
mark于此,希望有空时有高人能解决
sql.append("select ts,te.teacherName" +
",case ts.labId when 0 then '无' else (select lb.labName from LabBase lb where lb.labId=ts.labId) end as A4" +
",case ts.collegeCode when '00' then '无' else (select co.collegeName from College co where co.collegeCode=ts.collegeCode) end as A5" +
",te.isLock,te.teacherNumber,ts.labId " +
"from TeaStatistics ts,Teacher te where ts.teacherId=te.teacherId ");
就这样就报错了
ERROR 2012 四月 04 10:39:35,216org.hibernate.hql.PARSER (org.hibernate.hql.ast.ErrorCounter.reportError(ErrorCounter.java:56)) - <AST>:0:0: unexpected AST node: query
ERROR 2012 四月 04 10:39:35,217org.hibernate.hql.PARSER (org.hibernate.hql.ast.ErrorCounter.reportError(ErrorCounter.java:56)) - <AST>:0:0: unexpected AST node: query
org.hibernate.hql.ast.QuerySyntaxException: unexpected AST node: query [select ts,te.teacherName,case ts.labId when 0 then '无' else (select lb.labName from entityAndDAO.LabBase lb where lb.labId=ts.labId) end as A4,case ts.collegeCode when '00' then '无' else
(select co.collegeName from entityAndDAO.College co where co.collegeCode=ts.collegeCode) end as A5,te.isLock,te.teacherNumber,ts.labId from entityAndDAO.TeaStatistics ts,entityAndDAO.Teacher te where ts.teacherId=te.teacherId and ts.termYear ='2011-2012' ]
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.analyze(QueryTranslatorImpl.java:261)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:185)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:94)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1651)
at com.lab.action.TeacherAction.listYear(TeacherAction.java:714)
相关文章推荐
- Exception:hibernate HQL不充分支持 case when语句?
- hibernate hql case when 子查询报java.lang.NullPointerException错误
- 使用hibernate的hql语句做查询报错 org.hibernate.hql.internal.ast.QuerySyntaxException: user is not mapped
- 关于hql执行带有case when 的语句问题,另:数据表的倒置
- hibernate分组与聚合查询(原生sql和使用case when then else end的hql)
- 如何用ORM支持SQL语句的CASE WHEN?
- Hibernate 之 hql 语句执行字段过滤查询
- 关于oracle中查询语句 decode和 case when 的用法
- hibernate的hql查询语句总结
- hibernate-mysql中hql语句的表名首字母大写其他小写?并不是这样的
- org.hibernate.hql.ast.QuerySyntaxException: unexpected token 的解决
- Mysql 一条SQL语句实现批量更新数据,update结合case、when和then的使用案例
- Hibernate hql查询语句 Count:统计函数 Min:求最小值函数 Max:求最大值函数 Sum:求和函数 Avg:求平均数函数
- WebLogic发布S2SH应用时提示ClassNotFoundException: org.hibernate.hql.ast.HqlToken异常
- Exception in thread "main" org.hibernate.HibernateException: 'hibernate.dialect' must be set when no
- case when 嵌套sql语句
- Hibernate的HQL语句的select语句问题
- org.hibernate.hql.ast.QuerySyntaxException:XX is not mapped
- Caused by: org.hibernate.hql.ast.QuerySyntaxException: TkltEmpQuitProcess is not mapped. 问题解决
- case...when语句使用