The performance penalty of Class.forName when parsing JPQL and Criteria queries
Introduction While reviewing this Hibernate Pull Request, I stumbled on the HHH-10746 Jira issue. After doing some research, I realized that this issue was reported multiple times in the past 10 years: HHH-1810 HHH-4959 HHH-11246 In this post, I’m going to explain why this issue was causing performance issues, and how it got fixed.
How to customize an entity association JOIN ON clause with Hibernate @JoinFormula
Introduction As I explained in this previous article, you can map calculated properties using Hibernate @Formula, and the value is generated at query time. In this post, you’ll see how you can use a custom SQL fragment to customize the JOIN relationship between two entities, or an entity and a collection of embeddable types.
How to map calculated properties with Hibernate @Generated annotation
Introduction As I explained in this previous article, you can map calculated properties using Hibernate @Formula, and the value is generated at query time. In this post, you’ll see how you can calculate an entity property at INSERT or UPDATE time.
How does MySQL result set streaming perform vs fetching the whole JDBC ResultSet at once
Introduction I read a very interesting article by Krešimir Nesek regarding MySQL result set streaming when it comes to reducing memory usage. Mark Paluch, from Spring Data, asked if we could turn the MySQL result set streaming by default whenever we are using Query#stream or Query#scroll. That being said, the HHH-11260 issue was created, and I started working on it. During Peer Review, Steve Ebersole (Hibernate ORM team leader) and Sanne Grinovero (Hibernate Search Team Leader) expressed their concerns regarding making such a change. First of all, the MySQL result set streaming… Read More
How to map calculated properties with JPA and Hibernate @Formula annotation
Introduction As I explained in this StackOverflow question, mapping calculated properties is very easy with JPA and Hibernate. In this post, I’m going to demonstrate how you can derive some entity property based on one or multiple persistent entity attributes.
A beginner’s guide to SQL injection and how you should prevent it
Introduction One of my readers asked me to answer the following StackOverflow question. Right from the start, I noticed that the entity query was constructed by concatenating strings, which can expose your application to SQL Injection attacks. Unfortunately, I’ve been seeing this problem over and over throughout my career, and not all developers are aware of the serious risk associated with SQL Injection. For this reason, this post is going to demonstrate what damage can SQL Injection do to your system.
How to call MySQL stored procedures and functions with JPA and Hibernate
Introduction This article is part of a series of posts related to calling various relational database systems stored procedures and database functions from Hibernate. The reason for writing this down is because there are many peculiarities related to the underlying JDBC driver support and not every JPA or Hibernate feature is supported on every relational database.
How to resolve the Hibernate global database schema and catalog for native SQL queries
Introduction When your relation database system uses multiple schemas, then you can instruct Hibernate to use a global schema using the hibernate.default_schema configuration property: While Hibernate can imply the default schema whenever dealing with entity queries, for native queries, you need a little trick. This post is going to demonstrate how you can imply the default schema for native SQL queries as well.
The best way to implement equals, hashCode, and toString with JPA and Hibernate
Bytecode enhancement and toString Last week, Mark Struberg, who is an Apache Software Foundation member and OpenJPA contributor, made the following statement:
How to use external XML mappings files (outside of JAR) with JPA and Hibernate
Introduction Flemming Harms has asked a very good question on Twitter: Basically, we want to move the JPA XML mappings outside of the application JAR so that we can change the mapping without affecting the jar file.

