title: Search by many optional parameters in spring data jpa repository
body: <p>So I have tables comment and author. I want to build complex search bar with many optional parameters. I want filter comments with optional author firstname/lastname and some flags like popularity(based on comment rating).</p>
  
  <p>As I dont know how to write it using spring data jpa repository I ve been thinking on writing it as native query with @Query annotation, smth like this should work</p>
  
  <pre><code>Select c.* from comment c join author a on a.id = c.author_id
  Where (:firstname = '' or (:firstname = a.firstname)) 
  And (:lastname = '' or (:lastname = a.lastname))
  And (:popular = false or (c.rating &gt; 25))
  </code></pre>
  
  <p>Is there option to write it using spring data jpa?</p>
  
  <p>In future I plan to add more parameters and pagination for example. Using spring it would be like 1 minute with sql query I will lost few hours.</p>
  
  <p>Is there are some best practices in such cases?</p>