How to avoid the Hibernate Query Cache N+1 issue
Introduction I recently answered this question on the Hibernate forum, and since it’s a very good one, I decided to turn it into an article. In this post, we will describe how the N+1 query issue is generated when using the second-level Hibernate Query Cache.
9 High-Performance Tips when using PostgreSQL with JPA and Hibernate
Introduction To get the most out of the relational database in use, you need to make sure the data access layer resonates with the underlying database system. In this article, we are going to see what you can do to boost up performance when using PostgreSQL with JPA and Hibernate.
How to map an immutable entity with JPA and Hibernate
Introduction In this article, you are going to find out how to map an immutable entity when using JPA and Hibernate. If your Domain Model requires that a given entity should not be modified by the data access logic, Hibernate can enforce this requirement if the entity is marked with the @Immutable annotation.
PostgreSQL SERIAL or IDENTITY column and Hibernate IDENTITY generator
Introduction When using PostgreSQL, it’s tempting to use a SERIAL or BIGSERIAL column type to auto-increment Primary Keys. PostgreSQL 10 also added support for IDENTITY, which behaves in the same way as the legacy SERIAL or BIGSERIAL type. This article will show you that SERIAL, BIGSERIAL, and IDENTITY are not a very good idea when using JPA and Hibernate.
How to use a JVM or database auto-generated UUID identifier with JPA and Hibernate
Introduction In this article, we are going to see how to use a UUID entity identifier that is auto-generated by Hibernate either in the JVM or using database-specific UUID functions. Our Post entity looks as follows: The Post entity has a UUID identifier and a title. Now, let’s see how we can map the Post entity so that the UUID identifier be auto-generated for us.
How to get the actual execution plan for an Oracle SQL query using Hibernate query hints
Introduction While answering this question on the Hibernate forum, I realized that it’s a good idea to write an article about getting the actual execution plan for an Oracle SQL query using Hibernate query hints feature.
How to map a JPA entity to a View or SQL query using Hibernate
Introduction In this article, you are going to learn how to map a JPA entity to the ResultSet of a SQL query using the @Subselect Hibernate-specific annotation.
How to cache non-existing entity fetch results with JPA and Hibernate
Introduction Sergey Chupov asked me a very good question on Twitter: https://twitter.com/scadgek/status/946838214744203269 In this article, I’m going to show you how to cache null results when using JPA and Hibernate.
How to use the Hibernate Query Cache for DTO projections
Introduction On the Hibernate forum, I noticed the following question which is about using the Hibernate Query Cache for storing DTO projections, not entities. While caching JPQL queries which select entities is rather typical, caching DTO projections is a lesser-known feature of the Hibernate second-level Query Cache.

