How to optimize JPQL and Criteria API query plans with Hibernate Statistics

Introduction Every entity query, be it JPQL or Criteria API, needs to be parsed and compiled to an AST (Abstract Syntax Tree) in order to generate the associated SQL query. The entity query compilation takes time, as explained in this article so Hibernate provides a QueryPlanCache to store already-compiled plans. Starting with Hibernate 5.4, the Hibernate Statistics mechanism allows you to monitor the Query Plan Cache and this article will show you how to take advantage of this feature to speed up IN query performance. For an introduction about the Hibernate Statistics… Read More

PostgreSQL SERIAL 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. However, this article will show you that this is not a very good idea when using JPA and Hibernate.

How does Hibernate handle JPA Criteria API literals

Introduction The JPA specification is like a Java interface, However, when it comes to performance, implementation details matter a lot. That’s why, even if you use the JPA standard, you still need to know how the underlying provider implements the standard specification. For instance, if we take this tweet from Gareth Western: We can clearly see that there is an issue in the way literals might be handled by Hibernate when executing a Criteria API query. Therefore, in this article, we are going to see how literals are handled by Hibernate and… Read More

What’s new in JPA 2.2 – Stream the result of a Query execution

Introduction Now that the JPA 2.2 Review Ballot was approved, let’s start analyzing some of the new additions to the standard which have been supported by Hibernate for quite some time already. In this article, we are going to see how the JPA 2.2 Stream query results are supported by Hibernate and the caveats of using database cursors just to limit the amount of data that needs to be fetched.