Card 02/ 06

ExampleDifficulty: Intermediate1 min

A Query, Derived From a Method Name

No SQL, no @Query, no method body — the method's own name is enough for Spring Data to build a working query.

java
interface RideJpaRepository extends JpaRepository<RideEntity, Long> {
    List<RideEntity> findByStatusOrderByRequestedAtAsc(String status);
}
text
derived query found 2 rides, first id=2 (earlier time)
run in a container against a real H2 database — id 2 was requested earlier than id 1, and the ordering is real

findBy starts the query, Status names the field to filter on, OrderByRequestedAtAsc names the field and direction to sort by. Spring Data JPA parses the method name at startup and builds the equivalent JPQL — no implementation to write, and the query only exists because the name says exactly what it should return.