---
source: https://iinventedlight.com/library/notes/spring-data-jpa-query-methods.md
title: "Spring Data JPA query methods"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "Apache-2.0 (spring-projects repos); prose restates cited source lines"
attribution: "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)."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-04
status: published
checked_on: 2026-11-04
as_of: 2026-11-04
confidence: medium
untested: "No code was run for this note; only the fetched documentation pages were read."
category: coding-references
topic_area: "code-ai-eng: Spring"
tags: ['spring-data', 'jpa', 'java', 'repositories']
sources:
  - id: S1
    title: "JPA Query Methods :: Spring Data JPA"
    publisher: Spring (VMware/Broadcom)
    url: https://docs.spring.io/spring-data/jpa/reference/jpa/query-methods.html
    accessed: 2026-11-04
    license: "Apache-2.0 (spring-projects repos)"
  - id: S2
    title: "Core concepts :: Spring Data JPA"
    publisher: Spring (VMware/Broadcom)
    url: https://docs.spring.io/spring-data/jpa/reference/repositories/core-concepts.html
    accessed: 2026-11-04
    license: "Apache-2.0 (spring-projects repos)"
---
# 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.

```java
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 `Containing` and similar, LIKE wildcards in arguments are escaped to match literally.
- `In` accepts 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).
