How do you implement pagination with Spring Data JPA?
Build paginated queries with Spring Data JPA from entity to controller and test, including Page, Slice and keyset scrolling.
Spread Your Knowledge. Questions with answers, tutorials and articles, newest first.
Build paginated queries with Spring Data JPA from entity to controller and test, including Page, Slice and keyset scrolling.
Write Spring Data JPA query methods: derived names, JPQL and native @Query, Pageable, projections, @Modifying updates and @DataJpaTest tests.
@Version adds an optimistic lock counter to a JPA entity so concurrent updates are detected instead of overwritten. See the SQL, a conflict demo and handling.
Use @Version to enable optimistic locking in JPA. See how version checks prevent lost updates, how to handle conflicts, and which lock modes to use.
@JoinTable sets the name, foreign key columns and constraints of the join table behind a @ManyToMany or unidirectional @OneToMany mapping in JPA.
Define a JPA many-to-many relationship with @ManyToMany, @JoinTable and mappedBy, and learn when a join entity is the better design.
@ManyToOne maps many entities to one parent through a foreign key. See a working Employee and Department example, lazy fetching and how to avoid N+1 queries.
@OneToMany maps a parent's collection of child entities. See bidirectional and unidirectional mappings, cascade rules and how to avoid N+1 queries.
CacheManager maps cache names to providers in Spring Boot. See how auto-configuration picks one, how to configure TTL, and how to evict entries.
Enable caching with @EnableCaching, annotate service methods with @Cacheable and switch the default map to Caffeine for size limits and expiry.
In Spring Boot, @Cacheable plus a cache starter and provider gives you fast, configurable method caching. See Caffeine and Redis setups with expiry.
Follow one REST resource through reads and writes in Spring Boot, with server-side cache annotations, conditional GET with ETag, and a Cache-Control policy table.
Compare the main load testing tools for Spring Boot APIs, with Gatling, k6 and Locust examples and how to monitor the app with Actuator.
Plan a realistic workload, run Gatling, k6 or JMeter against a staging environment, and use Actuator metrics to find and fix Spring Boot bottlenecks.
MockMvc is a class, not an annotation. See how @WebMvcTest and @AutoConfigureMockMvc provide it and how to test REST endpoints with GET, POST and DELETE requests.
Test Spring Boot REST controllers with @WebMvcTest, MockMvc and @MockitoBean: GET, POST, DELETE, validation errors and JSON assertions.
@WebMvcTest loads only the web layer so controller tests run fast. See what it includes, a MockMvc example and the move from @MockBean to @MockitoBean.
Trigger each failure through MockMvc and assert status, media type and error body fields. Includes ProblemDetail handlers, validation tests and full-server checks.
TestRestTemplate is a test-friendly HTTP client for Spring Boot integration tests. It calls your running app on a random port and returns error responses instead of throwing.
@MockBean registers a Mockito mock in the Spring test context so you can isolate a component. It is deprecated in favour of @MockitoBean.