Spring Data JPA query methods
Answer: In Spring Data JPA, you declare a repository interface and get queries either derived from method names (findByLastnameAndAge) or written with @Query. Spring creates the implementation at runtime.
public interface UserRepository extends JpaRepository<User, Long> {
List<User> findByLastname(String lastname);
List<User> findByAgeGreaterThanAndActiveTrue(int age);
List<User> findByEmailContaining(String part);
List<User> findByIdIn(Collection<Long> ids);
@Query("select u from User u where u.emailAddress = ?1")
User findByEmailAddress(String email);
}
Concepts
- Spring Data treats domain types as entities, specifically aggregates.
Derived-query notes
- For
Containingand similar, LIKE wildcards in arguments are escaped to match literally. Inaccepts collections, arrays or varargs.
Prefer @Query when names get long.
Claims
- id: C1 claim: JPA queries can be defined manually or derived from the method name. source: S1 evidence: "supports defining a query manually as a String or having it being derived from the"
- id: C2 claim: Containing query arguments get sanitized. source: S1 evidence: "Containing, Contains the respective arguments for these queries will get sanitized."
- id: C3 claim: In and NotIn take any Collection, arrays or varargs. source: S1 evidence: "In and NotIn also take any subclass of Collection as a parameter"
- id: C4 claim: The central interface is Repository. source: S2 evidence: "The central interface in the Spring Data repository abstraction is Repository."
- id: C5 claim: Spring Data considers domain types to be entities, specifically aggregates. source: S2 evidence: "Spring Data considers domain types to be entities, more specifically aggregates."
Sources
- [S1] JPA Query Methods :: Spring Data JPA. Spring (VMware/Broadcom). https://docs.spring.io/spring-data/jpa/reference/jpa/query-methods.html . License: Apache-2.0 (spring-projects repos). Accessed 2026-11-04.
- [S2] Core concepts :: Spring Data JPA. Spring (VMware/Broadcom). https://docs.spring.io/spring-data/jpa/reference/repositories/core-concepts.html . License: Apache-2.0 (spring-projects repos). Accessed 2026-11-04.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted).
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Spring (VMware/Broadcom), JPA Query Methods :: Spring Data JPA, Apache-2.0 (spring-projects repos); Spring (VMware/Broadcom), Core concepts :: Spring Data JPA, Apache-2.0 (spring-projects repos).
Cite this
iinventedlight. 2026. "Spring Data JPA query methods." iinventedlight Library, iil:note:8p1pknsf, version of 2026-11-04. https://iinventedlight.com/library/notes/spring-data-jpa-query-methods/. License: CC-BY-4.0.
@misc{iil_note_8p1pknsf,
author = {{iinventedlight}},
title = {{Spring Data JPA query methods}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-04},
url = {https://iinventedlight.com/library/notes/spring-data-jpa-query-methods/},
note = {Permanent ID iil:note:8p1pknsf. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com.
For language models and agents: start at /llms.txt. This page in Markdown: /library/notes/spring-data-jpa-query-methods.md.