The best way to use the JPA SqlResultSetMapping

Introduction In this article, I’m going to explain how to use the JPA SqlResultSetMapping, as well as the EntityResult, ConstructorResult, and ColumnResult options.

N+1 query problem with JPA and Hibernate

Introduction In this article, I’m going to explain what the N+1 query problem is when using JPA and Hibernate and what’s the best way to fix it. The N+1 query problem is not specific to JPA and Hibernate, as you can face this issue even if you are using other data access technologies.

A beginner’s guide to JPA persistence.xml file

Introduction In this article, I’m going to explain what is the purpose of the JPA persistence.xml configuration file, and how you can set up a Java Persistence application using the available XML tags or attributes. While Spring applications can bootstrap without needing an XML JPA configuration file, it’s still important to understand the meaning of each configuration option since Spring also offers an alternative way when building a Java Persistence LocalContainerEntityManagerFactoryBean or the Hibernate-specific LocalSessionFactoryBean.

Hypersistence Optimizer Runtime Scanner

Introduction The 2.0 version of the Hypersistence Optimizer has just arrived, and it comes with a runtime scanner that is capable of analyzing your JPA and Hibernate data access operations and queries and give you tips about how you can speed up your application. Along with the JPA and Hibernate mapping and configuration scanners, the runtime scanner makes Hypersistence Optimizer an indispensable tool for building High-Performance Java Persistence applications.

How to map a PostgreSQL ARRAY to a Java List with JPA and Hibernate

Introduction In this article, I’m going to show you how to map PostgreSQL ARRAY column types (e.g., text, int, double, enum, date, timestamp, UUID) to Java List entity attributes with JPA and Hibernate. While the Hibernate Types project has been supporting PostgreSQL ARRAY column types since the very first version, prior to version 2.9, you could only map database ARRAY columns to Java Array entity attributes, as illustrated by this article. Mapping database ARRAY columns to java.util.List entity attributes is a much better approach than using the previous Java Array option since,… Read More

How to return a Map result from a JPA or Hibernate query

Introduction In this article, I’m going to show you how you can return a Java Map result when executing a JPA query. I decided to write this article after answering a similar question on StackOverflow.

Multidimensional array mapping with JPA and Hibernate

Introduction In this article, I’m going to present the best way to map a Java multidimensional array when using JPA and Hibernate. While one-dimensional array types have long been supported by the Hibernate Types open-source project, starting with the 2.9 release, you can now persist multidimensional array entity attributes with JPA and Hibernate.

The best way to use a Hibernate ResultTransformer

Introduction In this article, I’m going to present the best way to use a Hibernate ResultTransformer so that you can customize the result set of a given JPA or Hibernate query. As I already explained, the Hibernate ResultTransformer is a very powerful mechanism, allowing you to customize a JPQL, Criteria API, or native SQL query result set in any possible way.

The best way to prevent JPA and Hibernate performance issues

Introduction In this article, I’m going to present the best way to prevent performance issues when using JPA and Hibernate. Many years ago, I used to work as a team leader, and, one day, the General Manager asked me to take a look at a project that was in big trouble. The application in question had been developed by a team of software developers for over 9 months, and the client had just tested in a production-like environment. The client got very upset when realizing that the application was barely crawling. For… Read More

How to migrate the hilo Hibernate identifier optimizer to the pooled strategy

Introduction In this article, I’m going to show you how to migrate from the legacy hilo sequence-based identifier optimizer to the pooled Hibernate strategy. I decided to write this article after having a discussion with Gerd Aschemann on Twitter about addressing the HHH-13783 Hibernate issue.