您的位置:首页 > 其它

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)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: