title: Search by the combination of multiple parameters via Native Query
body: <p>I'm currently working on a fetaure that will allow the system to search public services receipts by the combination of 6 parameters which can be null meaning that receipts shouldn't be filtered by this parameter:  accountNumber, amountRangeMin, amountRangeMax, dateRangeMin, dateRangeMax,  publicServiceId. However making a method for each combination of the parameters is not an option, I'm thinking that there must be a better way, at first my approach was as following: </p>
  
  <p>On my Service I have this method:</p>
  
  <pre><code>public Map&lt;String,Object&gt; findPublicServiceReceiptsByParams(Integer accountNumber, BigDecimal amountRangeMin,
          BigDecimal amountRangeMax, LocalDate dateRangeMin, LocalDate dateRangeMax, Integer publicServiceId) {
      Map&lt;String,Object&gt; publicServiceReceipts = new HashMap&lt;String,Object&gt;();
      String accountNumberFilter = !(accountNumber==null) ? accountNumber.toString() : "AccountNumberTableName";
      String amountRangeMinFilter = !(amountRangeMin==null) ? amountRangeMin.toString() : "table.AmountColumnName";
      String amountRangeMaxFilter = !(amountRangeMax==null) ? amountRangeMax.toString() : "table.AmountColumnName";
      String dateRangeMinFilter = !(dateRangeMin==null) ? dateRangeMin.toString() : "Table.ReceiptCreationDateColumn";
      String dateRangeMaxFilter = !(dateRangeMax==null) ? dateRangeMax.toString() : "Table.ReceiptCreationDateColumn";
      String publicServiceIdFilter = !(publicServiceId==null) ? publicServiceId.toString() : "table.publicServiceIdColumn";
      publicServiceReceipts = publicServiceReceiptRepository.findPublicServiceReceiptsByParams(accountNumberFilter,
              amountRangeMinFilter, amountRangeMaxFilter, dateRangeMinFilter, dateRangeMaxFilter,
              publicServiceIdFilter);
      return publicServiceReceipts;
  }
  </code></pre>
  
  <p>And then in my repository I had: </p>
  
  <pre><code>final static String FIND_PUBLIC_SERVICES_BY_ARGS = "Select (Insert whatever logic should go in here to select columns from receipts the where clause is the one that matters)"
          + "    WHERE ACT.ACT_AccountNumber=:accountNumberFilter\n"
          + "      AND PSE.PSE_Id=:publicServiceIdFilter\n"
          + "      AND PSR.PSR_CreateDate BETWEEN :dateRangeMinFilter AND :dateRangeMaxFilter\n"
          + "      AND PSR.PSR_Amount BETWEEN :amountRangeMinFilter AND :amountRangeMaxFilter\n"
          + " order by PSR.PSR_CreateDate desc";
  
  @Query(nativeQuery = true, value = FIND_PUBLIC_SERVICES_BY_ARGS)
  Map&lt;String, Object&gt; findPublicServiceReceiptsByParams(@Param("accountNumberFilter") String accountNumberFilter,
          @Param("amountRangeMinFilter") String amountRangeMinFilter,
          @Param("amountRangeMaxFilter") String amountRangeMaxFilter,
          @Param("dateRangeMinFilter") String dateRangeMinFilter,
          @Param("dateRangeMaxFilter") String dateRangeMaxFilter,
          @Param("publicServiceIdFilter") String publicServiceIdFilter);
  </code></pre>
  
  <p>}</p>
  
  <p>My reasoning was that if a parameter was null meant that whoever consumed the Web Service is not interested in that paramater so if that happens I set that variable as the Column Name so that it wouldn't affect in the WHERE clause and in theory make it simpler, but what I found was that It would send the names as Strings so it wouldn't be recognized as an sql statement which was the flaw in my thinking and as I said there must be another way other than writing each method for each combination, I appreciate any help :).</p>