High-Performance Java Persistence Newsletter, Issue 27
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 edition is this article which shows you how MySQL stores data/time information in TIMESTAMP
and DATETIME
columns and how you can handle time zone information.
On the 23rd of May, Hibernate turned 20. To celebrate this anniversary, I wrote this article, in which I’m sharing my Hibernate journey.
If you’re using SQL Server, then you should learn how Foreign Key locking works, as it can impact concurrency if you include all the table columns during an UPDATE, which is how the default Hibernate UPDATE works. For more details about this topic and why you should use @DynamicUpdate
with SQL Server, then check out this article.
Speaking of @DynamicUpdate
, if you are using JSON columns, then you should also set the entity to use a dynamic UPDATE statement, as otherwise, the JSON column will be sent to the database on every property change, even if the JSON column hasn’t been modified. For more details, check out this article.
PostgreSQL 14 will add a new JSON path expression that will allow you to better locate nested attributes. For more details, check out this article.
Using a RANDOM
function in the ORDER BY
clause allows you to shuffle results. However, as explained in this article, the performance might not be great if the table is fairly large. So, if you’re using PostgreSQL, this article explains how you can emulate this feature using a spatial column that can have an associated spgist
index.
If you’re Spring Data JPA, then JPA Entity Graphs can be useful with @Query
methods. For more details about how JPA Entity Graphs work, you can read this article.
Best Tweets
Here are the best tweets I posted since the last newsletter:
Today, @Hibernate turns 20!
— Vlad Mihalcea (@vlad_mihalcea) May 23, 2021
Happy birthday to one of the most successful @Java data access frameworks and to @1ovthafew for creating it! pic.twitter.com/BOZkZzaNOU
Frameworks come and go.
— Vlad Mihalcea (@vlad_mihalcea) May 22, 2021
Relational databases stay.
Next time you debug your application step into the framework code to see how it works.
— Vlad Mihalcea (@vlad_mihalcea) June 6, 2021
Not only that you'll understand the framework better, but you can discover new programming techniques as well.
Don't put work above your own health. Your career is a very long marathon, not a short sprint.
— Vlad Mihalcea (@vlad_mihalcea) June 1, 2021
If you try and fail, be proud.
— Vlad Mihalcea (@vlad_mihalcea) May 25, 2021
Most people won't even try.
Project Releases
Hibernate 5.5.0 has been released, adding support for Jakarta JPA 2.2 and 3.0.
If you are using Hibernate 5.4, then you might want to upgrade to the 5.4.32 version, which fixes several issues and add new improvements.
The 2.11 version of the Hibernate Types project has been released, and it provides a new JsonType
that works with PostgreSQL, MySQL, Oracle, SQL Server, and H2 without having to do any change in your mapping. With this improvement, you can address the portability issues of using DB-specific JSON columns.
If you’re using PostgreSQL, then you might be interested in the 13.3 release, which provides several bug fixes.
And, if you’re using MySQL, then check out the 8.0.25 release.

Get in touch with my latest articles!
StackOverflow Answers
The following StackOverflow answers have been trending over the past two weeks:
- What is the JPQL equivalent of the PostgreSQL
date_trunc('day', (entity.date AT TIME ZONE 'UTC'))
function when using JPA and Hibernate - Hibernate entity proxy initialization
- What is a natural identifier in Hibernate?
- How to use Hibernate Session.doWork for savepoints and nested transactions?
- Clarifying terminology – What does “hydrating” a JPA or Hibernate entity mean when fetching the entity from the DB
- What’s the JPA equivalent of the Hibernate @LazyToOne annotation?