title: if/case condition in Hibernate query language But getting unknown token
body: <p>I am trying to use following query But getting unknown token error for "else,=,end". Please guide anyone. Thanks</p>
  
  <pre><code>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
  </code></pre>
  
  <p>update :
  Please see stacktrace below as its showing some uexpected token.
  Stacktrace:</p>
  
  <pre><code>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.&lt;init&gt;(HQLQueryPlan.java:77)
  at org.hibernate.engine.query.HQLQueryPlan.&lt;init&gt;(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
  </code></pre>