Optimistic locking version property with JPA and Hibernate

Introduction In this article, we are going to see how optimistic locking version property works when using JPA and Hibernate. Most often, we overlook basic concepts and focus only on more advanced topics such as associations or queries, without realizing that basic mappings can also have a significant impact when it comes to persistence effectiveness and efficiency.

How to intercept and modify SQL queries with the Hibernate StatementInspector

Introduction A very useful, yet lesser-known, Hibernate feature is the ability to intercept and modify any auto-generated SQL statement using the Hibernate StatementInspector utility. In this article, we are going to see how the Hibernate StatementInspector mechanism works.

How to detect HHH000104 issues with hibernate.query.fail_on_pagination_over_collection_fetch

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… Read More

Why you should avoid EXTRA Lazy Collections with Hibernate

Introduction In this article, you are going to learn why using EXTRA Lazy Collections with Hibernate is a bad idea since it can lead to N+1 query issues and cause performance problems. The reason I wanted to write this article is that I keep seeing it mentioned in StackOverflow or the Hibernate forum.

How does the entity version property work when using JPA and Hibernate

Introduction In this article, I’m going to show you how the JPA @Version entity property works when using Hibernate. The most significant benefit of adding a version property to a JPA entity is that we can prevent the lost update anomaly, therefore ensuring that data integrity is not compromised.