A custom repository in Spring Data JPA is created by defining a repository interface that extends JpaRepository (or CrudRepository) with your entity and ID types, optionally adding your own derived or @Query-annotated methods beyond the built-in CRUD operations.
A ProductRepository needs both the standard CRUD methods and a custom method to find discounted products, so it extends JpaRepository and adds a derived method, findByDiscountGreaterThan(BigDecimal amount), without needing to write any SQL by hand.
public interface ProductRepository extends JpaRepository<Product, Long> {
List<Product> findByDiscountGreaterThan(BigDecimal amount);
@Query("SELECT p FROM Product p WHERE p.category = :category")
List<Product> findByCategory(@Param("category") String category);
}A concise interview answer is
I extend JpaRepository with the entity and ID type to get all the standard CRUD, paging, and sorting behavior for free, then add my own methods either through Spring Data's derived-query naming or with @Query for anything more custom. For logic too complex to express declaratively, I'd add a separate custom interface and Impl class that Spring Data automatically wires in.
Last updated: 11 November 2026
Previous question: What are the main features of Spring Data JPA?
Next question: What is the difference between CrudRepository and JpaRepository?