High-Performance Java Persistence Newsletter, Issue 60

Imagine having a tool that can automatically detect JPA and Hibernate performance issues. Wouldn’t that be just awesome?

Well, Hypersistence Optimizer is that tool! And it works with Spring Boot, Spring Framework, Jakarta EE, Java EE, Quarkus, or Play Framework.

So, enjoy spending your time on the things you love rather than fixing performance issues in your production system on a Saturday night!

Introduction

Welcome to a new issue of the High-Performance Java Persistence Newsletter in which we share articles, videos, workshops, and StackOverflow answers that are very relevant to any developer who interacts with a database system using Java.

Articles

The pick of this week is this article about using the BUFFERS option in the PostgreSQL EXPLAIN ANALYZE so that we can better understand the IO impact of a given SQL query. Using BUFFERS will help you understand whether data is scanned from the in-memory Shared Buffers using logical reads or whether it comes from the OS Cache or the disk using physical reads.

Talking about performance, it’s important to know that, by default, PostgreSQL is pre-configured for running on machines that have few resources. For this reason, if you want to set up a production or QA environment, you need to change several settings to get the best out of your database. For more details about these settings you might want to change, check out this article.

Another very good article I read is this one from Lukas Eder about writing efficient Top N queries.

While the JPA EntityManager and the Hibernate Session that extends it provide you with a Persistence Context that can auto-detect entity changes and batch the modifications so that fewer statements are sent to the database, Hibernate also provides a StatelessSession. Prior to Hibernate 6, the StatelessSession was not very convenient, as it lacked support for batching. However, if you migrated to Hibernate 6, then you should know that the StatelessSession can now batch statements for you. For more details about this topic, check out this article.

Speaking of Hibernate 6, if you are using OffsetDataTime in your entities, then you could map the associated ZoneOffset to a separate database column. For more details about how you can achieve this, check out this article.

When executing an SQL query, the relation database system uses statistics to determine how many records would match the provided filtering criteria. Based on these cardinality estimates, the database can determine the execution plan with the least cost in terms of database resources. However, if the statistics are not accurate, then the generated execution plans might perform badly. For more details about this topic, check out this article.

If you are wondering when you should use Value Objects, such as Java Records, and when you should use JPA entities, then check out this article, as it covers this topic in detail.

Project Releases

The 6.4.4 version and 6.4.3 versions of Hibernate ORM have been released, so if you’re using Hibernate 6.4 in your application, then these new versions provide plenty of bug fixes.

The 3.7.3 version and 3.7.2 of the Hypersistence Utils project have been released, providing better support for Hibernate 6.4.

PostgreSQL 16.2 has been released, and it provides a lot of bug fixes for the PostgreSQL 16 version.

The 12.6 version of the Microsoft SQL Server JDBC Driver was released, bringing you support for Java 21, as well as various other configuration options.

Get in touch with my latest articles!

StackOverflow Answers

The following StackOverflow answers have been trending since the last newsletter episode:

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.