Vlad Mihalcea

Java and Database Newsletter, Issue 1

Imagine having a tool that can automatically detect if you are using JPA and Hibernate properly. Hypersistence Optimizer is that tool!

Introduction

I started my newsletter in November 2015, and every time I was publishing a new article, I would send it to my newsletter subscribers as well.

This year, I decided to change the format of my newsletter. Instead of creating a new issue for every article, the newsletter will now contain links to the best articles I read over the past two weeks.

Read More

Multidimensional array mapping with JPA and Hibernate

Imagine having a tool that can automatically detect if you are using JPA and Hibernate properly. Hypersistence Optimizer is that tool!

Introduction

In this article, I’m going to present the best way to map a Java multidimensional array when using JPA and Hibernate.

While one-dimensional array types have long been supported by the Hibernate Types open-source project, starting with the 2.9 release, you can now persist multidimensional array entity attributes with JPA and Hibernate.

Read More

The best way to use a Hibernate ResultTransformer

Imagine having a tool that can automatically detect if you are using JPA and Hibernate properly. Hypersistence Optimizer is that tool!

Introduction

In this article, I’m going to present the best way to use a Hibernate ResultTransformer so that you can customize the result set of a given JPA or Hibernate query.

As I already explained, the Hibernate ResultTransformer is a very powerful mechanism, allowing you to customize a JPQL, Criteria API, or native SQL query result set in any possible way.

Read More

The best way to prevent JPA and Hibernate performance issues

Imagine having a tool that can automatically detect if you are using JPA and Hibernate properly. Hypersistence Optimizer is that tool!

Introduction

In this article, I’m going to present the best way to prevent performance issues when using JPA and Hibernate.

Many years ago, I used to work as a team leader, and, one day, the General Manager asked me to take a look at a project that was in big trouble.

The application in question had been developed by a team of software developers for over 9 months, and the client had just tested in a production-like environment.

The client got very upset when realizing that the application was barely crawling. For instance, I was told that a query had been running for 10 hours without showing any signs of stopping.

After analyzing the project, I identified many areas that could have been improved, and that’s how my passion for high-performance data access was born.

Read More

How to migrate the hilo Hibernate identifier optimizer to the pooled strategy

Imagine having a tool that can automatically detect if you are using JPA and Hibernate properly. Hypersistence Optimizer is that tool!

Introduction

In this article, I’m going to show you how to migrate from the legacy hilo sequence-based identifier optimizer to the pooled Hibernate strategy.

I decided to write this article after having a discussion with Gerd Aschemann on Twitter about addressing the HHH-13783 Hibernate issue.

Read More

A beginner’s guide to SQL CROSS JOIN

Imagine having a tool that can automatically detect if you are using JPA and Hibernate properly. Hypersistence Optimizer is that tool!

Introduction

In this article, we are going to see how a CROSS JOIN works, and we will also make use of this SQL join type to build a poker card game.

Read More

How does the 2PL (Two-Phase Locking) algorithm work

Imagine having a tool that can automatically detect if you are using JPA and Hibernate properly. Hypersistence Optimizer is that tool!

Introduction

The 2PL (Two-Phase Locking) algorithm is one of the oldest concurrency control mechanisms used by relational database systems to guarantee data integrity.

In this article, I’m going to explain how the 2PL algorithm works and how you can implement it in any programming language.

Read More

Bulk update optimistic locking with JPA and Hibernate

Imagine having a tool that can automatically detect if you are using JPA and Hibernate properly. Hypersistence Optimizer is that tool!

Introduction

In this article, we are going to see how we can adjust a bulk update statement so that it takes optimistic locking into consideration.

While Hibernate has been supporting versioned HQL queries for a very long time, it’s actually very easy to achieve this goal even with standard JPQL or JPA Criteria API.

Read More

PostgreSQL trigger consistency check

Imagine having a tool that can automatically detect if you are using JPA and Hibernate properly. Hypersistence Optimizer is that tool!

Introduction

In this article, we are going to see how to implement a non-trivial consistency check using a PostgreSQL INSERT and UPDATE trigger.

By using a database trigger after executing an INSERT or UPDATE, we can ensure that the sum of salaries in a given department does not exceed the maximum budget allocated for the given department.

Read More

The best way to fix the Hibernate MultipleBagFetchException

Imagine having a tool that can automatically detect if you are using JPA and Hibernate properly. Hypersistence Optimizer is that tool!

Introduction

If you’ve been using Hibernate for some time, there is a good chance you bumped into a MultipleBagFetchException issue:

org.hibernate.loader.MultipleBagFetchException: cannot simultaneously fetch multiple bags

In this article, we are going to see the reason Hibernate throws the MultipleBagFetchException as well as the best way to solve this issue.

Read More