title: Suggestion for implementation of search filter with many2many relationship between two entites
body: <p>I want to implement /search rest method that will filter my Product object for the given parameters and return me a pageable set of products that are filtered.</p>
  
  <p>I was reading about Specification interface and Criteria API but i am having difficulties in implementing the solution.</p>
  
  <p>Product entity:</p>
  
  <pre><code>@Entity
  public class Product implements Serializable {
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private Long productId;
  
      @NotEmpty(message = "The product name must not be null.")
      private String productName;
  
      private String productDescription;
  
      @Min(value = 0, message = "The product price must no be less then zero.")
      private double productPrice;
  
      @Min(value = 0, message = "The product unit must not be less than zero.")
      private int unitInStock;
  
      @ManyToMany
      @JoinTable(name = "category_product", joinColumns = @JoinColumn(name = "product_id"), inverseJoinColumns = @JoinColumn(name = "category_id"))
      private Set&lt;Category&gt; categories = new HashSet&lt;&gt;();
  
  </code></pre>
  
  <p>As i want the user to be able to search by category name also,bedsides a price range and unitInStock which is separate entity and it is linked with @ManyToMany relationship ,i want to have a method that would look something like:</p>
  
  <pre><code>
  @GetMapping("/search")
      public ResponseEntity&lt;Set&lt;Product&gt;&gt; advancedSearch(@RequestParam(name="category") String categoryName,
                                                         @RequestParam(name="price") double price,
                                                         @RequestParam(name="unitInStock") int unitInStock  ){
  
      }
  
  </code></pre>
  
  <p>Category entity:</p>
  
  <pre><code>@Entity
  public class Category implements Serializable {
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private Long categoryId;
  
      @NotEmpty(message = "Can not be null")
      private String CategoryName;
  
      @ManyToMany(mappedBy = "categories")
      @JsonBackReference
      private Set&lt;Product&gt; products = new HashSet&lt;&gt;();
  
  </code></pre>