Skip to content

Commit 020309c

Browse files
authored
Merge pull request #2338 from lucamolteni/2025-06-18-hibernate-7-on-quarkus
Hibernate 7 on Quarkus: each new version brings a better database experience
2 parents 3b6612d + 32e28f3 commit 020309c

File tree

3 files changed

+124
-0
lines changed

3 files changed

+124
-0
lines changed

_data/authors.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,3 +605,10 @@ mmaler:
605605
job_title: "Senior Technical Writer at Red Hat; IBM"
606606
twitter: "mickeymaler"
607607
bio: "Senior Technical Writer and Blogger at Red Hat"
608+
lmolteni:
609+
name: "Luca Molteni"
610+
email: "volothamp@gmail.com"
611+
emailhash: "cd40128e044f39d7063b5cfdeace80f6"
612+
job_title: "Principal Software Engineer"
613+
twitter: "volothamp"
614+
bio: "Principal Software Engineer at Red Hat / IBM"
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
---
2+
layout: post
3+
title: 'Hibernate 7 on Quarkus: each new version brings a better database experience'
4+
date: 2025-06-26
5+
tags: hibernate, database, jpa
6+
synopsis: A roundup on the new upgrades of Hibernate on Quarkus.
7+
author: lmolteni
8+
---
9+
:imagesdir: /assets/images/posts/hibernate7
10+
ifdef::env-github,env-browser,env-vscode[:imagesdir: ../assets/images/posts/hibernate7]
11+
12+
=== Introduction
13+
Hibernate is improving at a very fast speed, and so is its integration with Quarkus, as great database access is a key part of the Quarkus experience.
14+
The latest Quarkus 3.24 release upgrades Hibernate to version 7, a major upgrade that implies some breaking changes, and thus will requires paying attention to the https://docs.jboss.org/hibernate/orm/7.0/migration-guide/migration-guide.html[migration guide] when upgrading.
15+
Developers working on Hibernate and Quarkus are constantly collaborating, so here’s a quick peek at what happened over the last few months and at what Quarkus users might expect in the future.
16+
17+
=== License and Governance Updates
18+
Both Quarkus and Hibernate are now projects of the https://www.commonhaus.org[Commonhaus Foundation], a non-profit organization dedicated to creating a collaborative environment for open-source libraries.
19+
Since the upgrade to Hibernate 7, Quarkus and all modules of Hibernate now share the same open-source license: the https://www.apache.org/licenses/LICENSE-2.0[Apache License Version 2.0].
20+
21+
=== Hibernate ORM 7.0 Updates
22+
The new version of Hibernate brings better performance and https://docs.jboss.org/hibernate/orm/7.0/whats-new/whats-new.html[all kinds of new features], some of which improve the developer experience, such as https://docs.jboss.org/hibernate/orm/7.0/whats-new/whats-new.html#session-find-multiple[using `findMultiple()` and `getMultiple()`] to efficiently fetch entities in batches.
23+
24+
==== Support for Jakarta Data
25+
https://jakarta.ee/specifications/data/1.0/jakarta-data-1.0[Jakarta Data] is a simpler way to write data-accessing applications, and it’s been supported in Quarkus since https://in.relation.to/2024/11/04/data-in-quarkus/[November 2024]. We suggest giving it a try, as it enables a very quick and easy implementation of the DAO/repository patterns, without any boilerplate code and in a type-safe manner. Simply include the `jakarta.data:jakarta.data-api` dependency with the latest version of Quarkus, i.e.:
26+
27+
[source,xml]
28+
----
29+
<dependency>
30+
<groupId>jakarta.data</groupId>
31+
<artifactId>jakarta.data-api</artifactId>
32+
</dependency>
33+
----
34+
35+
Here’s an example of how a simple repository can be written:
36+
37+
[source,java]
38+
----
39+
@Repository
40+
public interface Library {
41+
42+
@Find
43+
Optional<Book> byIsbn(String isbn);
44+
45+
@Query("""
46+
select b.isbn, b.title, listagg(a.name, ' & ')
47+
from Book b join b.authors a
48+
group by b
49+
order by b.isbn
50+
""")
51+
List<Summary> summarize();
52+
}
53+
----
54+
55+
This topic deserves a deeper dive, so let us know if you're interested, as we could provide more content.
56+
57+
In the meantime, you can always refer to the https://quarkus.io/version/main/guides/hibernate-orm#jakarta-data-2[dedicated Quarkus guide] to get started quickly, and to the https://docs.jboss.org/hibernate/orm/7.0/repositories/html_single/Hibernate_Data_Repositories.html[corresponding documentation in Hibernate ORM] for more advanced usage.
58+
59+
60+
==== New Restrictions API
61+
After the deprecation of the old Hibernate Criteria API, developers were still missing its simplicity, so the Hibernate team introduced a new https://docs.jboss.org/hibernate/orm/7.0/introduction/html_single/Hibernate_Introduction.html#restrictions-and-ordering[Restriction API] that even has new features, such as the possibility to further restrict an already-written JPQL/HQL query.
62+
63+
[source,java]
64+
----
65+
List<Book> books =
66+
SelectionSpecification.create(Book.class,
67+
"""
68+
from Book where discontinued = false
69+
""")
70+
.restrict(Restriction.startsWith(Book_.title, "hibernate"))
71+
.sort(Order.desc(Book_.title))
72+
.createQuery(session)
73+
.setPage(Page.first(50))
74+
.getResultList();
75+
----
76+
77+
This feature can also be used with https://docs.jboss.org/hibernate/orm/7.0/repositories/html_single/Hibernate_Data_Repositories.html#dynamic-restrictions[Hibernate Data Repositories] (the Hibernate implementation of the Jakarta Data API), and create a repository that allows filtering without having to write any JPQL/HQL code:
78+
79+
```java
80+
@Find
81+
List<Book> books(Restriction<Book> restriction,
82+
Order<Book> order);
83+
```
84+
85+
When user will call the method, they can pass the `Restriction` objects to filter the wanted book.
86+
87+
```java
88+
var books =
89+
library.books(Restriction.contains(Book_.title, "Hibernate"),
90+
Order.of(_Book.title.ascIgnoreCase(),
91+
_Book.isbn.asc()));
92+
```
93+
94+
=== Hibernate Reactive together with Hibernate ORM
95+
96+
A long-awaited feature is the ability to https://github.com/quarkusio/quarkus/issues/13425[mix Hibernate ORM and Hibernate Reactive extensions] in the same Quarkus application. Without this feature, making the two extensions coexist required workarounds that are now unnecessary as, since Quarkus 3.2.4, it's now possible to mix the two.
97+
98+
Hibernate Reactive is a powerful reactive data access abstraction, but its advantages vary per project. Instead of dictating usage, we now enable users to experiment easily with both Hibernate ORM and Reactive. Projects using Hibernate ORM can add the Reactive extension, create reactive resources reusing mapped entities, run tests and benchmarks, and determine if it suits their specific needs and scalability goals. While using both, it’s easier to choose the most suitable approach for different use cases. Another benefit is that it makes it easier to migrate in small steps from one to the other as necessary.
99+
100+
Panache users will also have this possibility starting from https://github.com/quarkusio/quarkus/issues/46096[Panache 2.0]
101+
102+
=== Injection of the SchemaManager
103+
104+
The Hibernate Schema Manager is a powerful tool to generate DDL scripts out of Java objects. Its power is now available to be used in Quarkus via dependency injection. This is particularly useful when https://docs.jboss.org/hibernate/orm/7.0/introduction/html_single/Hibernate_Introduction.html#testing[writing tests] letting you programmatically control when to do schema export, schema validation, data cleanup, and schema cleanup.
105+
106+
=== The Future
107+
108+
The teams have many plans for the future of these important projects: the DevUI of Quarkus will be enhanced with improvements to the developer experience, with the possibility of https://github.com/quarkusio/quarkus/issues/39584[executing arbitrary HQL queries] to try out the syntax and experiment with test data and https://github.com/quarkusio/quarkus/issues/43723[generating migration scripts on the fly]
109+
110+
image::console.gif[scaledwidth=100%]
111+
112+
We’re working on improving the Hibernate Reactive extension as well, by providing support for https://github.com/quarkusio/quarkus/pull/48007[Named Data Sources and Named Persistence Units].
113+
114+
Also, as part of giving a better experience for the user, the Quarkus and Hibernate teams constantly collaborate on performance and efficiency improvements. For example, an optimization that https://hibernate.atlassian.net/browse/HHH-18326[avoids the need for an `IdentityHashMap` to track persistence entities] improved the performance by https://github.com/hibernate/hibernate-orm-benchmark/pull/15[8% while running a simple query of 100-1000 immutable entities], end even more when dealing with persistent collections.
115+
And that's just _one_ improvement among many, and not the last one: even bigger performance improvements are expected in the future.
116+
117+
https://quarkus.io/guides/update-quarkus[Take a look at the new release] and let us know what you think!
779 KB
Loading

0 commit comments

Comments
 (0)