Why you should use compact table columns

Introduction In this article, I’m going to explain you should use compact table columns when designing your database schema. By using compact table columns, you can cache more table records and index entries and, therefore, speed up your SQL queries. Database caching As I explain … | Continue reading


@vladmihalcea.com | 1 day ago

High-Performance Java Persistence Newsletter, Issue 69

Introduction Welcome to a new issue of the High-Performance Java Persistence Newsletter in which we share articles, videos, workshops, and StackOverflow answers that are very relevant to any developer who interacts with a database system using Java. Articles The pick of this week … | Continue reading


@vladmihalcea.com | 1 month ago

Avoid using Set for bidirectional JPA OneToMany collections

Introduction In this article, we are going to see why there is no benefit in using the Set collection type when mapping a bidirectional JPA OneToMany association. While the @OneToMany annotation can be used to map both unidirectional and bidirectional associations, as I explained … | Continue reading


@vladmihalcea.com | 1 month ago

JTA Transaction Type

Introduction In this article, we are going to analyze how the JTA transaction type works. Since this is the default transaction type when using Jakarta EE or Java EE applications, it’s very important to understand how JTA transactions work, especially since Spring Boot or Spring … | Continue reading


@vladmihalcea.com | 2 months ago

The best way to determine the optimal connection pool size

Introduction In this article, we are going to see the best way to determine the optimal connection pool size using the FlexyPool auto-incrementing pool strategy. If you are unfamiliar with the reason why database applications need a connection pool, then check out this article fi … | Continue reading


@vladmihalcea.com | 2 months ago

High-Performance Java Persistence Newsletter, Issue 68

Introduction Welcome to a new issue of the High-Performance Java Persistence Newsletter in which we share articles, videos, workshops, and StackOverflow answers that are very relevant to any developer who interacts with a database system using Java. Articles The pick of this week … | Continue reading


@vladmihalcea.com | 2 months ago

How to use LazyConnectionDataSourceProxy with Spring Data JPA

Introduction In this article, we are going to see how we can use the LazyConnectionDataSourceProxy with Spring Data JPA to acquire the database connection as late as possible and, therefore, reduce transaction response time. For an introduction to how Spring transactions manage d … | Continue reading


@vladmihalcea.com | 2 months ago

RESOURCE_LOCAL JPA Transaction Type

Introduction In this article, we are going to analyze how the RESOURCE_LOCAL JPA transaction type works. Since this is the default transaction type when using Spring Boot or Spring Data JPA, it’s very important to understand how transactions are managed when using the RESOURCE_LO … | Continue reading


@vladmihalcea.com | 3 months ago

High-Performance Java Persistence Newsletter, Issue 67

Introduction Welcome to a new issue of the High-Performance Java Persistence Newsletter in which we share articles, videos, workshops, and StackOverflow answers that are very relevant to any developer who interacts with a database system using Java. Articles The pick of this week … | Continue reading


@vladmihalcea.com | 3 months ago

Eleven years of blogging

Eleven years later! Eleven years ago today, I decided to create my blog on WordPress.com, and this is the first article I published. Every year, on my blog anniversary, I write a report about the achievements that were made possible by having this very blog. If you are curious ab … | Continue reading


@vladmihalcea.com | 3 months ago

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. Domain Model Considering we have the following PostC … | Continue reading


@vladmihalcea.com | 3 months ago

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 … | Continue reading


@vladmihalcea.com | 3 months ago

Embeddable Inheritance with JPA and Hibernate

Introduction In this article, we are going to see how we can map embeddable inheritance when using JPA and Hibernate. The feature described in this article is available since version 6.6 of Hibernate ORM, so if you haven’t yet upgraded, then you have one more reason to consider i … | Continue reading


@vladmihalcea.com | 4 months ago

High-Performance Java Persistence Newsletter, Issue 66

Introduction Welcome to a new issue of the High-Performance Java Persistence Newsletter in which we share articles, videos, workshops, and StackOverflow answers that are very relevant to any developer who interacts with a database system using Java. Articles The pick of this week … | Continue reading


@vladmihalcea.com | 4 months ago

Custom Spring Boot Actuator Endpoint

Introduction In this article, we are going to see how we can create a custom Spring Boot Actuator endpoint in order to export our own metrics and events. Spring Boot Actuator is a Spring Boot module that provides support for tracing and monitoring. And, while by default, we get v … | Continue reading


@vladmihalcea.com | 4 months ago

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 JP … | Continue reading


@vladmihalcea.com | 4 months ago

High-Performance Java Persistence Newsletter, Issue 65

Introduction Welcome to a new issue of the High-Performance Java Persistence Newsletter in which we share articles, videos, workshops, and StackOverflow answers that are very relevant to any developer who interacts with a database system using Java. Articles The pick of this week … | Continue reading


@vladmihalcea.com | 5 months ago

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 an … | Continue reading


@vladmihalcea.com | 5 months ago

How to use symbolic links to move the DB data folder

Introduction In this article, we are going to see how we can use symbolic links to move the DB data folder. The reason why I needed to move the data folder from the C to the D Windows partition was because the C partition was running out of disk space. DB data folder A relational … | Continue reading


@vladmihalcea.com | 5 months ago

Book Review – Beginning Helidon

Introduction My friend, Dmitry Aleksandrov, has been very generous in giving me a copy of his Helidon book, which he co-authored with Dmitry Kornilov and Daniel Kec. Since I was interested in learning about Helidon, I decided to read this book and see what approach it takes to de … | Continue reading


@vladmihalcea.com | 6 months ago

High-Performance Java Persistence Newsletter, Issue 64

Introduction Welcome to a new issue of the High-Performance Java Persistence Newsletter in which we share articles, videos, workshops, and StackOverflow answers that are very relevant to any developer who interacts with a database system using Java. Articles The pick of this week … | Continue reading


@vladmihalcea.com | 6 months ago

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 dea … | Continue reading


@vladmihalcea.com | 6 months ago

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 dec … | Continue reading


@vladmihalcea.com | 7 months ago

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. Domain Model Let’s consider we have the following post and post_comment tables: The post_comment child table has a one-to-ma … | Continue reading


@vladmihalcea.com | 7 months ago

High-Performance Java Persistence Newsletter, Issue 63

Introduction Welcome to a new issue of the High-Performance Java Persistence Newsletter in which we share articles, videos, workshops, and StackOverflow answers that are very relevant to any developer who interacts with a database system using Java. Articles The pick of this week … | Continue reading


@vladmihalcea.com | 7 months ago

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. Upsert As I explained in this article, if you have this use case where you need to either INSERT or UPDATE … | Continue reading


@vladmihalcea.com | 7 months ago

PostgreSQL COPY result set to file

Introduction In this article, we are going to se how we can use the PostgreSQL COPY command to export a large result set to an external file. ETL (Extract, Transform, Load) When implementing an ETL (Extract, Transform, Load) process, you might have to extract a large result set f … | Continue reading


@vladmihalcea.com | 7 months ago

PostgreSQL plan_cache_mode

Introduction In this article, we are going to analyze the PostgreSQL plan_cache_mode setting and see when it’s useful to override a given generic plan using the the force_custom_plan strategy. Domain Model Let’s assume we have the following post table: The post_status type is an … | Continue reading


@vladmihalcea.com | 8 months ago

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. JPA … | Continue reading


@vladmihalcea.com | 8 months ago

High-Performance Java Persistence Newsletter, Issue 62

Introduction Welcome to a new issue of the High-Performance Java Persistence Newsletter in which we share articles, videos, workshops, and StackOverflow answers that are very relevant to any developer who interacts with a database system using Java. Articles The pick of this week … | Continue reading


@vladmihalcea.com | 8 months ago

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. One-To-One table relationship As I explained in this article, in a one-to-one table relationship, the parent and the child tables s … | Continue reading


@vladmihalcea.com | 8 months ago

How to calculate percentiles with SQL PERCENTILE_CONT

Introduction In this article, we are going to investigate how to calculate percentiles with the SQL PERCENTILE_CONT function. Domain Model Let’s consider we have the following quotes table that holds the historical price values of various stocks and indexes: The quotes table is p … | Continue reading


@vladmihalcea.com | 9 months ago

PostgreSQL FOR UPDATE vs FOR NO KEY UPDATE

Introduction In this article, we are going to investigate the difference between the PostgreSQL FOR UPDATE and FOR NO KEY UPDATE when locking a parent record and inserting a child row. Domain Model To see the difference between the PostgreSQL FOR UPDATE and FOR NO KEY UPDATE lock … | Continue reading


@vladmihalcea.com | 9 months ago

High-Performance Java Persistence Newsletter, Issue 61

Introduction Welcome to a new issue of the High-Performance Java Persistence Newsletter in which we share articles, videos, workshops, and StackOverflow answers that are very relevant to any developer who interacts with a database system using Java. Articles The pick of this week … | Continue reading


@vladmihalcea.com | 9 months ago

PostgreSQL Heap-Only-Tuple or HOT Update Optimization

Introduction In this article, we are going to analyze how PostgreSQL Heap-Only-Tuple or HOT Update optimization works, and why you should avoid indexing columns that change very frequently. PostgreSQL Tables and Indexes Unlike SQL Server or MySQL, which store table records in a C … | Continue reading


@vladmihalcea.com | 9 months ago

PostgreSQL Index Types

Introduction In this article, we are going to analyze the PostgreSQL Index Types so that we can understand when to choose one index type over the other. When using a relational database system, indexing is a very important topic because it can help you speed up your SQL queries b … | Continue reading


@vladmihalcea.com | 10 months ago

High-Performance Java Persistence Newsletter, Issue 60

Introduction Welcome to a new issue of the High-Performance Java Persistence Newsletter in which we share articles, videos, workshops, and StackOverflow answers that are very relevant to any developer who interacts with a database system using Java. Articles The pick of this week … | Continue reading


@vladmihalcea.com | 10 months ago

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 separat … | Continue reading


@vladmihalcea.com | 10 months ago

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 an … | Continue reading


@vladmihalcea.com | 10 months ago

PostgreSQL Performance Tuning Settings

Introduction In this article, we are going to explore various PostgreSQL performance tuning settings that you might want to configure since the default values are not suitable for a QA or production environment. As explained in this PostgreSQL wiki page, the default PostgreSQL co … | Continue reading


@vladmihalcea.com | 11 months ago

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 … | Continue reading


@vladmihalcea.com | 11 months ago

High-Performance Java Persistence Newsletter, Issue 59

Introduction Welcome to a new issue of the High-Performance Java Persistence Newsletter in which we share articles, videos, workshops, and StackOverflow answers that are very relevant to any developer who interacts with a database system using Java. Articles The pick of this week … | Continue reading


@vladmihalcea.com | 11 months ago

The race condition that led to bankruptcy

Learn how a race condition led to the bankruptcy of Flexcoin in 2014 after hackers stole all the available funds. | Continue reading


@vladmihalcea.com | 2 years ago

How to create a tech startup – a real-life story

Learn how you can create a tech startup. This is the real-life story of how I created RevoGain. | Continue reading


@vladmihalcea.com | 3 years ago

My Eight year journey of blogging about SQL and Java

Eight years and counting! It was September 2013, and I had always wanted to start a blog but had never found the motivation to do it. If you keep on waiting for the right time to do something, that day might never come. Either you start right away, or you just keep on lying to yo … | Continue reading


@vladmihalcea.com | 3 years ago

60 years of COBOL – past, present, and future

60 years of COBOL, and, most likely, it's here for the future. This article is an interview with Adrian Tot about the state of COBOL. | Continue reading


@vladmihalcea.com | 4 years ago

The Anatomy of Connection Pooling

Introduction All projects I’ve been working on have used database connection pooling and that’s for very good reasons. Sometimes we might forget why we are employing one design pattern or a particular technology, so it’s worth stepping back and reason on it. Every technology or t … | Continue reading


@vladmihalcea.com | 4 years ago

How Does the 2PL (Two-Phase Locking) Algorithm Work

Learn what the 2PL (Two-Phase Locking) algorithm works and how it can guarantee data integrity strict serializability in a relational database system. | Continue reading


@vladmihalcea.com | 5 years ago