Spring Transaction and Connection Management

Introduction In this article, we are going to see how Spring handles transaction and database connection management. I decided to write this article because this topic has been requested recurringly by the students taking my High-Performance Java Persistence training.

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.

The best way to use Spring Data query methods

Introduction In this article, we are going to see how Spring Data query methods are built, when you should use them, and especially when you should avoid them. I decided to write this article after answering this StackOverflow question, which depicts an 87-character-long Spring Data query method. TL;DR, Don’t write query methods that cannot even fit on the screen.

Scaling a Spring application with a YugabyteDB cluster

Introduction In this article, we are going to see that scaling the data access layer of a Spring application can be done very easily with a YugabyteDB cluster. As I explained in this article, YugabyteDB is an open-source distributed SQL database that offers all the benefits of a typical relational database (e.g., SQL, strong consistency, ACID transactions) with the advantages of a globally-distributed auto-sharded database system (e.g., NoSQL document databases).

Spring MDC Transaction Logging

Introduction In this article, we are going to see how to configure a Spring application to use MDC (Mapped Diagnostic Context) for transaction logging. This technique is going to help us inject the Persistence Context information as well as the associated database transaction identifier in all the log entries emitted from within a @Transactional service method.

The best way to do the Spring 6 migration

Introduction In this article, we are going to see how you can get the most out of the Spring 6 and Hibernate 6 migration. The tips in this article are based on the work I’ve done to add support for Spring 6 in Hypersistence Optimizer and the High-Performance Java Persistence project.

The Spring Data JPA findById Anti-Pattern

Introduction In this article, we are going to see how the Spring Data JPA findById method can become an Anti-Pattern when using it to reference parent entity associations.

How to write a custom Spring Data Base Repository

Introduction In this article, we are going to see how we can write a custom Spring Data base Repository that you could use instead of the default ones, like the overly common JpaRepository. Now, why would you even want to do that? Well, most of the default repositories extend the CrudRepository, which provides some very questionable defaults, like findAll or deleteAll that shouldn’t be really inherited by every single data access Repository instance.

The Spring Data findAll Anti-Pattern

Introduction In this article, we are going to see why inheriting the default Spring Data findAll method in every data access Repository is a terrible Anti-Pattern.