title: Case when expression in JPQL
body: <p>I am having problem when I implement 'CASE WHEN' condition with JPQL</p>
  
  <pre><code>&lt;dependency&gt;
          &lt;groupId&gt;org.hibernate.javax.persistence&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-jpa-2.0-api&lt;/artifactId&gt;
  &lt;/dependency&gt;
  
  
  select u 
    from user u
    where u.languageId = case
    when :userLanguageId is null then :managerLanguageID
    else :userLanguageId 
     end
  </code></pre>
  
  <p>I want to get data based on managerLanguageID if data corresponding userLanguageId is null. So the problem occurs when I use parameter with THEN keyword. but it works fine if I set the parameter manually like: </p>
  
  <pre><code>select u 
    from user u
    where u.languageId = case
    when :userLanguageId is null then 1
    else :userLanguageId 
     end
  </code></pre>
  
  <p>btw,.Here is the exception it throws:</p>
  
  <blockquote>
    <p>Caused by: java.lang.IllegalArgumentException:
    java.lang.ClassCastException:
    org.hibernate.hql.internal.ast.tree.ParameterNode cannot be cast to
    org.hibernate.hql.internal.ast.tree.SelectExpression  at
    org.springframework.data.jpa.repository.query.SimpleJpaQuery.(SimpleJpaQuery.java:73)
      at
    org.springframework.data.jpa.repository.query.SimpleJpaQuery.fromQueryAnnotation(SimpleJpaQuery.java:132)
      at
    org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$DeclaredQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:114)</p>
  </blockquote>