How to Implement a Search Feature in Spring Data JPA
Implement search in Spring Data repositories using derived queries, @Query, Specifications and pagination, and learn when to use each approach.
Spread Your Knowledge. Questions with answers, tutorials and articles, newest first.
Implement search in Spring Data repositories using derived queries, @Query, Specifications and pagination, and learn when to use each approach.
Page carries the content of one page plus total elements and pages. Learn how repositories fill it, how to tune the count query and when to scroll instead.
Accept a Pageable, apply offset, size and sort to your query, and return a Page with PageableExecutionUtils in a custom repository.
@Repository registers a data access class as a Spring bean and translates persistence exceptions into DataAccessException for technology-neutral handling.
Derive queries from method names, write JPQL or native SQL with @Query, and add custom fragments when you need the EntityManager. Spring Boot 3 examples.
JpaRepository adds CRUD, paging, sorting, flush and batch operations to a Spring Data interface with no implementation. See its methods and query options.
onException() lets Apache Camel routes retry, handle or redirect failures per exception type. See handled, continued, backoff and scope with working examples.
Create a fragment interface and an Impl class, then extend it from your repository to add custom queries to Spring Data JPA while keeping derived methods.
@DiscriminatorValue gives each JPA entity subclass a marker value in the discriminator column, so Hibernate can load the right type from shared tables.
Use onException, a dead letter channel and doTry/doCatch to retry, reroute or recover failed messages in Apache Camel routes on Spring Boot.
Use @DiscriminatorValue and @DiscriminatorColumn to tell JPA which subclass each row represents in single-table and joined inheritance.
ChoiceDefinition is the model class behind Camel's choice() DSL. Learn how when() and otherwise() route messages, and how to avoid the missing end() bug.
@DiscriminatorColumn names the column JPA uses to tell subclasses apart in an inheritance hierarchy. Attributes, types and a SINGLE_TABLE example.
Learn how @DiscriminatorColumn and @DiscriminatorValue tell JPA which subclass a row belongs to, including types, defaults and Hibernate's formula option.
Camel's Choice EIP routes each message by its content. Learn choice, when and otherwise with Simple, JSONPath, XPath, YAML and XML examples.
Learn the purpose of the Apache Camel Processor interface: process an Exchange in a route, use lambdas and beans, handle errors and test it.
TABLE_PER_CLASS gives every concrete entity its own table with all inherited columns. Learn its mapping, id restrictions and query trade-offs against other strategies.
Annotate the root entity with @Inheritance(strategy = JOINED) to give each class its own table, and see the trade-offs against other strategies.
from() defines where a Camel route starts and to() sends the message onward. See examples with files, choice routing, toD and error handling in Camel 4.
SINGLE_TABLE stores a whole entity hierarchy in one table, split by a discriminator column. See a Jakarta Persistence example, trade-offs and alternatives.