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.
-
TimezoneStorageType – Hibernate’s improved timezone mapping
Working with timestamps with timezone information has always been a struggle. Since Java 8 introduced the Date and Time API, OffsetDateTime and ZonedDateTime have become the most obvious and commonly used types to model a timestamp with timezone information. And you might expect that choosing one of them should be the only thing you need…
-
How to map composite column types with Hibernate
When most developers design their table and entity models, they create tables that only use basic column types and map these to basic entity attributes. Even though these are the most commonly used types, they are not the only ones supported by modern relational databases and Hibernate. You can also use composite, JSON, and XML…
-
How to use PostgreSQL’s JSONB data type with Hibernate
Most databases offer many proprietary features besides the known SQL standard. One example is PostgreSQL’s JSONB data type which allows you to store JSON documents efficiently in a database column. You could, of course, store the JSON document in a text column. That column type is part of the SQL standard. Hibernate and all other…
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.
-
How to generate DAOs and queries with Hibernate
Executing a query with Hibernate requires several lines of repetitive boilerplate code, and many developers have complained about that for years. You have to instantiate a Query object and set all bind parameter values before you can finally execute the query. Since version 6.3.1, Hibernate has solved this with an improved metamodel generator that provides…
-
Using Window Functions with Hibernate 5 & 6
SQL is an incredibly powerful query language. It provides sheer endless possibilities to extract and transform information. One example of that is a window function. It enables you to perform operations on subsets of the table rows available in your query. The PostgreSQL documentation explains window functions as: A window function performs a calculation across a set…
-
Hibernate-specific extensions to the Criteria API
Most developers know that the JPA specification defines the string-based JPQL query language and that Hibernate extends it to support things like database-specific functions, window functions, and set-based operations. But most developers don’t know that since version 6, Hibernate has done the same for JPA’s Criteria API. Extending an API is, of course, a little more complex…