Exception:hibernate HQL不充分支持 case when语句?

这两天写代码时又碰到这个问题,放到从前就直接改成用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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值