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
You need to add @Param
annotation to the method variable name so that you can refer it in your query. Code you have written is absolutely fine. In case you need access to EntityManager
, then you will need a custom repository.
@Query("from Auction a join a.category c where c.name=:categoryName")
public Iterable findByCategory(@Param("categoryName") String categoryName);
@Param
can be omitted when using Java 8 and compiling with -parameters
.
Hope that helps.
Tip: Whenever you post a question always post the exception details as well. It helps in understanding the issue.