title: JPQL check in parameter not null and then execute query
body: <p>I have some parameters which can be null or can be not null.</p>
  
  <p>What I want to do is to execute query only with parameters which are not null.</p>
  
  <p>For example I have:</p>
  
  <pre><code>String param1;
  String param2;
  </code></pre>
  
  <p>And I want to do something like this:</p>
  
  <pre><code> If ( param1 != null &amp;&amp; param2 != null ) {
      Query q = em.createQuery("SELECT a FROM Advert where a.property = param1 and a.property2= param2);
   }
  
   if( param1 == null &amp;&amp; param2 != null ) {
      Query q = em.createQuery("SELECT a FROM Advert where  a.property2= param2")
   }
  
   if( param1 != null &amp;&amp; param2 == null ) {
      Query q = em.createQuery("SELECT a FROM Advert where  a.property= param1");
   }
  </code></pre>
  
  <p>Is it possible to do this not using if statements
   but with jpql query string? 
  ( because I have more than two parameters and it is not so convenient to check so many cases)</p>