Card 02/ 06
All 6 cards
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.
interface RideJpaRepository extends JpaRepository<RideEntity, Long> {
List<RideEntity> findByStatusOrderByRequestedAtAsc(String status);
}derived query found 2 rides, first id=2 (earlier time)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.