As you can expect from a new major version, Hibernate 6 brought many changes. The most noticeable ones were the update to JPA 3 and the removal of Hibernate’s proprietary and long-deprecated Criteria API. But these are, of course, not the only ones. The release already brought us better performance, new features, and several improvements to existing mapping and query features.
You can find my articles explaining all the new and improved features below. But before you focus on the new things, let me quickly tell you how to migrate your application to Hibernate 6.
In contrast to previous releases, version 6 includes a few breaking changes. Most of them were caused by JPA 3, which had to rename all packages and configuration parameters. And the Hibernate team created some themselves by removing a few deprecated APIs. But don’t worry. It’s not as bad as it might sound. You can migrate most projects in a few hours. I summarized the necessary steps in the article on the right and documented the migration of an example project in the Persistence Hub.
New Mapping Features
Hibernate 6 introduced several new mapping features and improved existing ones. To name just a few, you can now map composite column types and use Java Records to model Embeddable. And you can benefit from the improved mapping of ZonedDateTime, a more flexible instantiation of Embeddables, and a drastically simplified mapping of JSON columns.
-
Java Records as Embeddables with Hibernate 6
Since the release of Java’s record feature, I got asked how you could use records with Hibernate. Until Hibernate 6, I had to tell you that JPA and Hibernate only supported records as DTO projections. That finally changed with the release of Hibernate 6.0 and got even easier with Hibernate 6.2. Unfortunately, you still can’t use…
-
How to generate UUIDs as primary keys with Hibernate
Most developers prefer numerical primary keys because they are efficient to use and easy to generate. But that doesn’t mean that a primary key has to be a number. UUIDs, for example, have gained some popularity over recent years. The main advantage of a UUID is its (practical) global uniqueness which provides a huge advantage…
-
Sequence naming strategies in Hibernate 6
Hibernate 6 introduced a new configuration parameter and an interface to define the implicit naming strategy for database sequences and tables used to generate primary key values. When you migrate an existing application to Hibernate 6, you quickly recognize that change because the default naming strategy has changed. Due to that, Hibernate might try using…
New Query Features
In addition to the new mapping capabilities, the Hibernate team also drastically improved Hibernate’s query capabilities. E.g., you can now use window functions in your JPQL queries, a streamlined version of Hibernate’s popular ResultTransformer, and Hibernate’s proprietary extensions to the Criteria API.
-
Hibernate’s ResultTransformer in Hibernate 4, 5 & 6
Hibernate implements JPA’s standardized constructor expressions and @SqlResultSetMappings to map the results of your queries. And it also supports proprietary ResultTransformers. They provide a powerful and flexible way to map the result of your JPQL, Criteria, and native SQL query to a specific object structure. This can be entity or DTO objects, java.util.List or java.util.Map…
-
MutationQuery and SelectionQuery in Hibernate 6
One of the smaller changes in Hibernate 6 that can easily get overlooked, which Steve Ebersole presented in a recent Expert Session in the Persistence Hub, is the introduction of the MutationQuery and SelectionQuery interfaces. It allows the separation between queries that change data and the ones that select it from the database. Older Hibernate…