title: jpa query with two parameters
body: <p>I have two parameters say name and description of state entity. </p>
  
  <ol>
  <li>If the name and desc are not mentioned, then the query should return all the states. </li>
  <li>If the only name is mentioned the filtered list of states which matched the passed name should be returned </li>
  <li>If the only desc is passed, the list of states matching the description should be returned. </li>
  <li>Only if both name and description are passed, then the result should contain all the states which either match the name or description should be returned.</li>
  </ol>
  
  <p>I have written the JPA query like below:</p>
  
  <pre><code>@Query("select s from State s where (:name is null or s.name = :name) or (:desc is null or s.desc=:desc)")
  List&lt;State&gt; fetchStates(@Param("name") String name,  @Param("desc") String description, Pageable pageable);
  </code></pre>
  
  <p>SQL query generated:</p>
  
  <pre><code>select state0_.state_id as state1_24_, state0_.created_date as creation2_24_, state0_.desc as descript3_24_, state0_.name as name4_24_ from state state0_ where ? is null or state0_.name=? or ? is null or state0_.desc=? order by state0_.name desc limit ?
  </code></pre>
  
  <p>I guess, if we have more than one parameter, we cannot write the dynamic query to get the desired result. Please let me know if my assumption is right else where I am missing. I am new to JPA.</p>