Spring Data JPA: A method name is a query

Spring parses the name and writes the JPQL, so simple finders need no query at all.

Code
interface OrderRepository extends JpaRepository<Order, Long> {

    List<Order> findByStatus(Status status);

    List<Order> findByStatusAndTotalGreaterThan(Status status, BigDecimal min);

    Optional<Order> findFirstByCustomerIdOrderByPlacedAtDesc(Long customerId);

    long countByStatus(Status status);
}
Output
findByStatusAndTotalGreaterThan generates:
select o from Order o where o.status = ?1 and o.total > ?2
Advertisement

Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.

Published 2026-08-11