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.
How to map a PostgreSQL Range column type with JPA and Hibernate
Introduction In this article, we are going to see how to map the PostgreSQL range column types with JPA and Hibernate. Luckily, you don’t have to implement a custom Hibernate type for the PostgreSQL range column type since the Hypersistence Utils project already provides support for it.
How to map a PostgreSQL HStore entity property with JPA and Hibernate
Introduction The Hypersistence Utils open-source project allows you to map a great variety of database types that are not supported natively by Hibernate ORM (e.g. JSON, ARRAY, YearMonth, Month, INET addresses). In this article, we are going to see how you can map a PostgreSQL HStore type, which allows you to store key/value pairs, to a Java Map entity property when using JPA and Hibernate.
How to map a PostgreSQL Enum ARRAY to a JPA entity property using Hibernate
Introduction The Hypersistence Utils OSS project allows you to map JSON, ARRAY, YearMonth, Month or database-specific columns (e.g., INET addresses). In this article, we are going to see how you can map a PostgreSQL Enum ARRAY type to a Java array entity property when using JPA and Hibernate.
How to bind custom Hibernate parameter types to JPA queries
Introduction In this article, we are going to see how we can bind a custom Hibernate parameter type to a JPA query. I decided to write this article after one of my hibernate-types framework users created this very interesting issue on GitHub.
The best way to initialize LAZY entity and collection proxies with JPA and Hibernate
Introduction In this article, we are going to see the best way to initialize LAZY proxies and collections when using JPA and Hibernate. I decided to write this article because there are way too many resources available on the Internet that mislead the reader into using awkward and inefficient practices.