title: Hibernate Sub query inside case when statement
body: <p>I'm having a problem on executing HQL sub query inside case when statement.</p>
  
  <p>here is my code:</p>
  
  <pre><code>select case when a.entityId is null then 'invalid' else 
     (select b.entityName from tblName b where b.entityId =a.entityId) 
     end from tblEntity a
  </code></pre>
  
  <p>Thanks for any help!</p>
  
  <p>Ok.. here's the full stack trace</p>
  
  <pre><code>ERROR org.hibernate.hql.PARSER - &lt;AST&gt;:0:0: unexpected AST node: query
  Exception in thread "Thread-5" org.hibernate.hql.ast.QuerySyntaxException: unexpected AST node: query [select case when a.entityId is null then 'invalid' else 
         (select b.entityName from tblName b where b.entityId =a.entityId) 
         end from tblEntity a]
      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.&lt;init&gt;(HQLQueryPlan.java:101)
      at org.hibernate.engine.query.HQLQueryPlan.&lt;init&gt;(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)
  </code></pre>