title: How to write an HQL query that to handle optional input parameters
body: <pre><code> @Query("SELECT c FROM message c" 
         +" WHERE (CASE WHEN a=''    THEN 1=1 ELSE a= :a"
         + "           WHEN b=''     THEN 1=1 ELSE b= :b"
         + "           WHEN c=''     THEN 1=1 ELSE c= :c"
         + "           WHEN d=''     THEN 1=1 ELSE d= :d)")
  </code></pre>
  
  <p>I am trying to write an HQL query that has <em>optional</em> inputs of values a, b, c, and d.</p>
  
  <p>My goal is to have the query recognize if an input =' 'and then just move along with 1=1 essentially doing nothing.</p>
  
  <p>I keep getting error
  <em>antlr.NoViableAltException: unexpected token: =</em></p>
  
  <p>First the error token was "CASE" and now it is "=".</p>
  
  <p>Is the "1=1 approach" viable?
  Can I use CASE statements like this in HQL?</p>
  
  <p>Thank you</p>
  
  <p>UPDATED ATTEMPT:</p>
  
  <pre><code> @Query("SELECT c "
                 + "FROM message c" 
                 + " WHERE"
                 + " CASE (WHEN a != '' THEN a = :a"
                 + "    WHEN b != ''   THEN b = :b"
                 + "    WHEN c != ''   THEN c = :c"
                 + "    WHEN d != ''   THEN d = :d)"
  
  antlr.NoViableAltException: unexpected token: WHEN
  antlr.NoViableAltException: unexpected token: a
  antlr.NoViableAltException: unexpected token: THEN
  </code></pre>