0

我正在尝试使用以下查询,但出现“else,=,end”的未知令牌错误。请指导任何人。谢谢

select ta from TblApp ta inner join ta.tblEmp tbe where 
        case when :empId=0 then 1=1 else tbe.empId=:empId end 
        and case when :year=0 then 1=1 else ta.year=:year end 
        and case when :typeId=0 then 1=1 else ta.typeId=:typeId end

更新:请参阅下面的堆栈跟踪,因为它显示了一些 uexpected 令牌。堆栈跟踪:

org.hibernate.hql.ast.QuerySyntaxException: unexpected token: = near line 1, column 134 [select ta from TblApp ta inner join ta.tblEmp tbe where 
        case when :empId=0 then 1=1 else tbe.empId=:empId end 
        and case when :year=0 then 1=1 else ta.year=:year end 
        and case when :typeId=0 then 1=1 else ta.typeId=:typeId end ]
at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:31)
at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:24)
at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:59)
at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:261)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:159)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:113)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
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:1624)
at com.vbs.hr.portal.struts.dao.AppraisalDAO.selfAppraisal(AppraisalDAO.java:275)
at com.vbs.hr.portal.struts.bo.AppraisalBO.selfAppraisal(AppraisalBO.java:218)
at com.vbs.hr.portal.struts.actions.AppraisalAction.teamAppraisal(AppraisalAction.java:329)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.struts.actions.ActionDispatcher.dispatchMethod(ActionDispatcher.java:362)
at org.apache.struts.actions.ActionDispatcher.dispatchMethod(ActionDispatcher.java:336)
at org.apache.struts.actions.ActionDispatcher.execute(ActionDispatcher.java:223)
at com.vbs.hr.portal.struts.base.BaseAction.execute(BaseAction.java:48)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:425)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:228)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.displaytag.filter.ResponseOverrideFilter.doFilter(ResponseOverrideFilter.java:125)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at 
at java.lang.Thread.run(Thread.java:662)
2013-05-29 17:18:45 PARSER [ERROR] line 1:134: unexpected token: =
2013-05-29 17:18:45 PARSER [ERROR] line 1:137: unexpected token: else
2013-05-29 17:18:45 PARSER [ERROR] line 1:159: unexpected token: end
4

1 回答 1

0

在 where 子句中不允许 case,Tried 和/或运算符及其工作正常

于 2013-05-30T06:51:35.123 回答