title: How to do a "findByCategory" in a ManyToMany products schema in Spring JPA Repository class?
body: <p><em>I am new to Java Spring Frameworks and I know this title sounds too specific, but the answer to this question is useful for any similar many-to-many schemas. I searched a lot for this answer and found none. <strong>Please:</strong> read full body before downvote or relate to other questions.</em></p>
  
  <p>I have the entities <code>Product</code> and <code>Category</code> and they are <code>many-to-many</code> related and generated at <code>run-time</code>.</p>
  
  <p>In my <code>REST</code> application I have three important <code>end-points</code> that uses that schema:</p>
  
  <ol>
  <li><code>/category</code> to list all categories as a menu;</li>
  <li><code>/products?description=</code> to list products filtered by terms in description field;</li>
  <li><code>/category/{id}/products</code> to list products that are in this category.</li>
  </ol>
  
  <p>I have difficult with this last one, as I was told that I should use the <code>@Query</code> <em>annotation</em> to make a <code>join</code> and a <code>where</code> to get the job done. But I believe Spring JPA engineers could not leave this such common task outside the <em>JPA Way</em>.</p>
  
  <p>The second end-point has this method in its <strong>repository</strong>: </p>
  
  <pre><code>public Page&lt;Produto&gt; findByDescriptionIgnoreCaseContainingOrderByDescriptionAsc(String description, Pageable pageOptions);
  </code></pre>
  
  <p>The last end-point I was told it should be like:</p>
  
  <pre><code>@Query("select * from products p left join p.category c where c = ?1")
  public List&lt;Produto&gt; findByOrderByDescriptionAsc(Lond idCategory)
  </code></pre>
  
  <hr>
  
  <p><strong>Can I</strong> perform this search as <code>listByCategory(a way to get only one category)</code> <strong>without</strong> having to use the <code>@Query</code> annotation? If Yes, How?</p>