How to solve the PostgreSQL :: cast operator issue with JPA and Hibernate
Introduction While answering questions on the Hibernate forum, I stumbled on the following question regarding the PostgreSQL :: cast operation used in a JPA and Hibernate entity query. Since it’s a very interesting use case, I decided to turn the answer into a dedicated blog post.
The hibernate-types open-source project is born
Introduction Recently, I got a very interesting request from one of my readers. Since I’ve been providing many custom types to support JSON, ARRAY, or nullable Character types, I decided to start a new open-source project to make it easier for you to get these extra Hibernate Types.
The best way to map an Enum Type with JPA and Hibernate
Introduction Recently, I got a very good question on Twitter, and I decided that the best way to answer it is with a new article. In this article, we are going to see how various ways to map an Enum using JPA and Hibernate.
The best way to fix the Hibernate “firstResult/maxResults specified with collection fetch; applying in memory!” warning message
Introduction If you’ve been using Hibernate long enough, then you surely must have seen this WARN log message when doing pagination while join-fetching multiple entities. HHH000104: firstResult/maxResults specified with collection fetch; applying in memory! In this article, I’m going to show two ways you can to fix this issue.
How to map a composite identifier using an automatically @GeneratedValue with JPA and Hibernate
Introduction One of my readers asked me to answer the following StackOverflow question. While I already covered the best way to map composite identifiers with JPA and Hibernate, this use case is different because one column is automatically generated.
The best way to map a projection query to a DTO (Data Transfer Object) with JPA and Hibernate
Introduction In this article, I’m going to show you the best way to map a DTO projection when using JPA and Hibernate. While answering questions on the Hibernate forum, I stumbled on the following question. What was different than previous questions on the same topic was that the original poster realized the shortcoming of the JPA constructor expression which can be addressed elegantly by Hibernate. Because this has been a recurring theme on StackOverflow and the Hibernate forum, I decided to dedicate an article to the best way of mapping DTO projections… Read More
The best way to implement an audit log using Hibernate Envers
Introduction In this article, we are going to learn what is the best way to implement an audit log to track INSERT, UPDATE, and DELETE statements using Hibernate Envers. As previously explained, CDC (Change Data Capture) is an essential step to extract change events from an OLTP application to make them available to other modules in an enterprise system (e.g. caches, data warehouse). While Debezium is the most efficient way of doing CDC, it might be that you need a simpler solution in your project. Hibernate Envers is a Hibernate ORM extension… Read More
How to map a @ManyToOne association using a non-Primary Key column with JPA and Hibernate
Introduction While answering questions on the Hibernate forum, I stumbled on the following question about using the @ManyToOne annotation when the Foreign Key column on the client side references a non-Primary Key column on the parent side. In this article, you are going to see how to use the @JoinColumn annotation in order to accommodate non-Primary Key many-to-one associations.

