Hibernate SoftDelete annotation

Introduction In this article, we are going to see how we can use the Hibernate SoftDelete annotation to activate soft deleting for JPA entities. While, as I explained in this article, you can manually implement the soft delete mechanism using the @SQLDelete, @Loader and @Where annotations, it’s definitely much easier to just use the native Hibernate mechanism introduced in Hibernate 6.4 , which you can enable via the @SoftDelete annotation.

How to map Java Enum to custom values with JPA and Hibernate

Introduction In this article, we are going to see how we can map Java Enum to custom values when using JPA and Hibernate. While Hibernate provides several options to save Enum values, having the option to customize this mechanism is even better, as it will allow you to better deal with legacy applications or use cases that require you to reorder the Java Enum values.

How does the Hibernate JAVA_TIME_USE_DIRECT_JDBC setting work

Introduction In this article, we are going to see how the Hibernate JAVA_TIME_USE_DIRECT_JDBC setting works and what JDBC Driver supports this feature. This setting can be set programmatically, as illustrated by the following Spring Java-based configuration: Or you can set it declaratively in the Spring Boot application.properties configuration file like this:

Hibernate WITH RECURSIVE query

Introduction In this article, we are going to see how the Hibernate WITH RECURSIVE query works and how we can use it to fetch hierarchical data structures.

Hibernate ON CONFLICT DO clause

Introduction In this article, we are going to see how the Hibernate ON CONFLICT DO clause works, and how we can use it to execute an SQL UPSERT statement in a portable way.

Overriding FetchType.EAGER with fetchgraph

Introduction In this article, we are going to see how you can override the FetchType.EAGER strategy using the fetchgraph query hint. While this feature has been available in the JPA specification since version 2.1, Hibernate has only supported this feature since version 5.5.

The best way to use the JPA OneToOne optional attribute

Introduction In this article, we are going to see what is the best way we can use OneToOne optional attribute so that we can avoid N+1 query issues.

How to map the OffsetDateTime ZoneOffset with Hibernate TimeZoneColumn

Introduction In this article, we are going to see how we can map the OffsetDateTime ZoneOffset with the Hibernate TimeZoneColumn annotation. As I explained in this article, by default, Hibernate doesn’t store the time-zone offset of an OffsetDateTime entity attribute in a separate column. Instead, the OffsetDateTime is stored as a java.time.Instant that is relative to the UTC time zone. However, there are use cases when we need to save the associated ZoneOffset, and that’s exactly when you would use the TimeZoneColumn annotation.

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

Hibernate StatelessSession JDBC Batching

Introduction In this article, we are going to see how we can use the Hibernate StatelessSession in order to enable JDBC Batching for INSERT, UPDATE, and DELETE statements. While the StatelessSession has been available for more than 20 years, until Hibernate 6, its usefulness was rather limited since it lacked support for batching, as well as other cool features, such as UPSERT.