Vlad Mihalcea

How to detect HHH000104 issues with hibernate.query.fail_on_pagination_over_collection_fetch

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

Introduction

Recently, I noticed the hibernate.query.fail_on_pagination_over_collection_fetch configuration property that was introduced in Hibernate 5.2, and I had absolutely no idea it can be used to prevent the HHH000104 Hibernate issues.

As previously explained, if you want to overcome the “HHH000104: firstResult/maxResults specified with collection fetch; applying in memory!” issue, you have to either use 2 queries or a window function to fetch and limit the number of parent records while making sure you always fetch all their associated child entities.

Even if the HHH000104 issue is logged as a warning message, it might pass unnoticed when the amount of data is fairly low, only to become a significant performance issue when data starts accumulating.

In this article, I’m going to explain why you should always activate the hibernate.query.fail_on_pagination_over_collection_fetch configuration property and, instead of a warning message, you will get an exception that’s unlikely to go unnoticed.

Read More

How to expose Hibernate Statistics via JMX

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

Introduction

As already explained, Hibernate provides a very flexible statistics mechanism. The Hibernate metrics can be accessed either programmatically via the org.hibernate.stat.Statistics interface or via JMX (Java Management Extensions).

In this article, you are going to see how you can expose the Hibernate statistics metrics using JMX.

Read More

A beginner’s guide to Hibernate Statistics

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

Introduction

Hibernate provides a very powerful Statistics mechanism that, unfortunately, is lesser known. In this article, we are going to see how the Hibernate Statistics mechanism works, and how you can activate.

While the Hibernate Statistics mechanism is not enabled by default, you will see that many applications can benefit from using it, especially when it comes to determining cache effectiveness.

Read More

A beginner’s guide to database table relationships

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

Introduction

In a relational database, a relationship is formed by correlating rows belonging to different tables. A table relationship is established when a child table defines a Foreign Key column that references the Primary Key column of its parent table.

Every database table relationship is, therefore, built on top of Foreign Key columns, and there can be three table relationship types:

  • one-to-many is the most common relationship, and it associates a row from a parent table to multiple rows in a child table.
  • one-to-one requires the child table Primary Key to be associated via a Foreign Key with the parent table Primary Key column.
  • many-to-many requires a link table containing two Foreign Key columns that reference the two different parent tables.

In this article, we are going to describe all these three table relationships as well as their use cases.

Read More

How to implement a database job queue using SKIP LOCKED

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 implement a database job queue using SKIP LOCKED.

I decided to write this article while answering this Stack Overflow question asked by Rafael Winterhalter.

Since SKIP LOCKED is a lesser-known SQL feature, it’s a good opportunity to show you how to use it and why you should employ it, especially when implementing a job queue task.

Read More

Want to run your data access layer at warp speed?