Keyset Pagination with Spring Data WindowIterator

Introduction In this article, we are going to see how we can generate Keyset Pagination queries with the Spring Data WindowIterator utility. This is an alternative to the Blaze Persistence solution I documented in this article.

A beginner’s guide to Spring Data Envers

Introduction In this article, we are going to investigate the Spring Data Envers project and see how to get the best out of it. Hibernate Envers is a Hibernate ORM extension that allows us to track entity changes with almost no changes required on the application part. Just like Envers plugs into Hibernate ORM in order to build an audit log for entity changes, the Spring Data Envers project plugs into Spring Data JPA to provide audit logging capabilities to JPA Repositories.

How to integrate Jakarta Data with Spring and Hibernate

Introduction In this article, we are going to see how we can integrate Jakarta Data with Spring and Hibernate. Jakarta Data is a new Jakarta EE specification that provides a common API for building data Repositories and data access objects. If you are familiar with Spring Data JPA, you will see that Jakarta Data is very much inspired by this Spring API.

How to use Java Records with Spring Data JPA

Introduction In this article, we are going to see how we can use Java Records with Spring Data JPA Repositories. As I already explained, Java Records cannot be used as JPA entities since the Records are immutable, and JPA requires the entity class to have a default constructor and be modifiable, as that’s how the entity properties are populated when the entity is being fetched from the database. For this reason, this article will show you how to combine Java Records and JPA entities so that you get the best out of… Read More

How to cascade DELETE with Spring and Hibernate events

Introduction In this article, we are going to see how we can cascade the DELETE operation for unidirectional associations with Spring Data JPA and Hibernate events. Using Hibernate events to achieve this goal is an alternative to the bulk DELETE statement strategy, as it allows us to cascade the delete operation from a parent entity to its children when we cannot use the CascadeType mechanism.

How to cascade DELETE unidirectional associations with Spring Data JPA

Introduction In this article, we are going to see how to cascade DELETE the unidirectional associations with Spring Data JPA when we cannot rely on the CascadeType mechanism that propagates state transitions from parent to child entities.

The best way to use Spring Data JPA Stream methods

Introduction In this article, we are going to see what is the best way to use Spring Data JPA Stream query methods. When having to fetch a larger result set, the advantage of using a Java Stream is that the query result set could be fetched progressively instead of getting all the data at once.

Spring Data Query By Example

Introduction In this article, we are going to see how the Spring Data JPA Query By Example (QBE) feature works, when you should use it, and what limitations it has. While Spring Data JPA already provides a wide range of options to query data: query methods or the @Query annotation Spring Data JPA Specification custom Repository query methods The Spring Data Query By Example feature is meant to offer a way to decouple the data filtering logic from the query processing engine so that you can allow the data access layer clients… Read More

The best way to use the Spring Data JPA Specification

Introduction In this article, we are going to see what is the best way to use the Spring Data JPA Specification when combining multiple predicates with the result set ordering logic. While you can also use query methods or the @Query annotation to define your Spring Data queries, the Spring Data JPA Specification allows you to compose dynamically various filtering criteria, which may be very convenient when you’d, otherwise, end up with lots of query method permutations.

The best way to use JOIN FETCH and Pagination with Spring

Introduction In this article, we are going to see how we can use the JOIN FETCH clause when fetching a child collection eagerly while also limiting the number of parent records using pagination in a Spring Data JPA application. I decided to write this article because the most common solution used in many projects turns out to be extremely inefficient.