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.

Spring Data JPA entity locking

Introduction In this article, we are going to see what options Spring Data JPA offers for entity locking. We will see how we can apply a shared or exclusive row-level lock upon fetching one or multiple entities.

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.

The best way to fetch a Spring Data JPA DTO Projection

Introduction In this article, I’m going to show you what is the best way to fetch a Spring Data JPA DTO Projection. Apart from the basic use cases, we’re going to see how to fetch even hierarchical DTO structures using Spring Data JPA.

Spring Data JPA MultipleBagFetchException

Introduction In this article, I’m going to show you how to handle the MultipleBagFetchException thrown by Hibernate upon simultaneously fetching multiple collections with Spring Data JPA.

Spring Transaction Best Practices

Introduction In this article, I’m going to show you various Spring Transaction Best Practices that can help you achieve the data integrity guarantees required by the underlying business requirements. Data integrity is of paramount importance because, in the absence of proper transaction handling, your application could be vulnerable to race conditions that could have terrible consequences for the underlying business.

The best Spring Data JpaRepository

Introduction In this article, I’m going to show you the best way to use the Spring Data JpaRepository, which, most often, is used the wrong way. The biggest issue with the default Spring Data JpaRepository is the fact that it extends the generic CrudRepository, which is not really compatible with the JPA specification.

The best way to write a Spring Data Exists Query

Introduction In this article, I’m going to show you the best way to write a Spring Data Exists Query that’s efficient from an SQL perspective. While doing consulting, I’ve encountered several options that are commonly used without developers knowing there are actually better alternatives.

Spring Boot Application Properties

Introduction In this article, I’m going to show you the best way to configure the Spring Boot Application Properties file. This is not just theoretical advice. I applied all these tips when developing RevoGain, a web application that allows you to calculate the gains you realized while trading stocks, commodities, or crypto using Revolut.