title: How to write a custom CrudRepository method(@Query) to filter the result in my case
body: <p>I am new to Spring JPA and Repository stuff. I have an Auction class with a bunch of fields in it, and one of the field is category. I want a custom method in CrudRepository to filter the results by Category.name; </p>
  
  <pre><code>@XmlRootElement 
  @Entity(name="AUCTION")
  public class Auction implements Serializable{
  
      private static final long serialVersionUID = 1L;
  
      @Id
      String id;
  
      @Column
      @Size(min=5, max=200)
      String title;
  
      String description;
  
      @OneToOne(cascade={CascadeType.ALL})
      Category category;
  
      ....}
  </code></pre>
  
  <p>Category</p>
  
  <pre><code>@Entity(name="CATEGORY")
  //@NamedQuery(name="Category.findByName", query="select c from Category c where c.name=:name")
  public class Category implements Serializable{
  
      private static final long serialVersionUID = 3L;
  
      @Id
      @GeneratedValue(strategy=GenerationType.AUTO)
      private Integer id;
  
      private String name;
  
      public Category()
      {
  
      }
  </code></pre>
  
  <p>In the auction Repository, I added a method like this</p>
  
  <pre><code>@Repository
  public interface AuctionRepository extends CrudRepository&lt;Auction, String&gt;{
  
      @Query("from Auction a join a.category c where c.name=:categoryName")
      public Iterable&lt;Auction&gt; findByCategory(String categoryName);
  
  }
  </code></pre>
  
  <p>Its throwing an error. Omit this method and everything works fine. Someone told me that this type of custom methods could be declared in CrudRepository and Spring will take care of doing the right thing using the methodName and the query hint we gave. Could someone point me in the right direction Please.</p>