@Query
@Query is a Spring Data annotation that associates a repository method with an explicitly declared query for retrieving or modifying data.
Java Persistence with Spring Data and Hibernate epub
The @Query annotation is a Spring Data repository-method annotation that declares a query to execute instead of deriving one from the method name.
- How it is used
- Declares custom repository queries when method-name derivation is insufficient or unsuitable.
- How deep it goes
- Defines parameter binding, native-query portability, sorting, projections, SpEL, and runtime validation, but not query execution internals.
- Examples
- Uses UserRepository counts, filtered users, sorting, projections, relationship-table counts, and MongoDB equality, regular-expression, range, and field-selection queries.
- What you can do after
- Apply it via Spring Data repository interfaces to implement parameterized JPQL, SQL, native SQL, or MongoDB queries.
Read how Java Persistence with Spring Data and Hibernate epub explains @Query →
Spring in Action, Sixth Edition
@Query is a Spring Data annotation that associates a repository method with an explicitly specified database query.
- How it is used
- Defines repository queries directly when derived method names become unwieldy or insufficient.
- How deep it goes
- Explains explicit JPA queries and contrasts JDBC SQL requirements, without detailing query parsing or execution internals.
- Examples
- Uses a repository method that retrieves orders delivered in Seattle.
- What you can do after
- Apply @Query to define repository methods for custom JPA queries or Spring Data JDBC SQL queries.
Related concepts
- SQLconfigures · SQL is a standardized declarative language for defining, querying, and manipulating data and structures in relational database systems.
- Spring Expression Languageused by · Spring Expression Language is an expression language integrated with Spring for querying and manipulating object graphs and evaluating values, conditions, and configuration rules.
- query methodconfigures · A query method is a method that defines, constructs, refines, or evaluates a database query.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

