Skip to content

Commit 4fb0560

Browse files
lucamolteniyrodiere
authored andcommitted
Hibernate 7 on Quarkus: fixes
Restrictions and Jakarta Data together Remove title syntax Fix spelling Fix spelling Changed prog language Added link
1 parent 673f9de commit 4fb0560

File tree

1 file changed

+50
-27
lines changed

1 file changed

+50
-27
lines changed

_posts/2025-06-18-hibernate7-on-quarkus.adoc

Lines changed: 50 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,21 @@ synopsis: a roundup on the new upgrades of Hibernate on Quarkus
77
author: lmolteni
88
---
99
:imagesdir: /assets/images/posts/hibernate7
10+
ifdef::env-github,env-browser,env-vscode[:imagesdir: ../assets/images/posts/hibernate7]
1011

11-
=== Introduction ===
12+
=== Introduction
1213
Hibernate is improving at a very fast speed, and so is its Quarkus support, as great database access is a key part of the Quarkus experience.
1314
The new Quarkus 3.24 release upgrades Hibernate to version 7, a major upgrade that implies some breaking changes, and thus will require some investigation with the https://docs.jboss.org/hibernate/orm/7.0/migration-guide/migration-guide.html[migration guide] when upgrading.
1415
Developers working on Hibernate and Quarkus are constantly collaborating, so here’s a quick peek at what has happened in the last months and what Quarkus users might expect in the future.
1516

16-
=== License and Governance Updates ===
17+
=== License and Governance Updates
1718
Both Quarkus and Hibernate are now projects of the https://www.commonhaus.org[Commonhaus Foundation], a non-profit organization dedicated to the sustainability of open-source libraries.
1819
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]. Implementing a proper open-source approach is crucial to the success of the two projects.
1920

20-
=== Hibernate ORM 7.0 Updates ===
21+
=== Hibernate ORM 7.0 Updates
2122
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 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.
2223

23-
==== New Restrictions API ====
24-
After the deprecation of the 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 query using JPQL/HQL.
25-
26-
[source,java]
27-
----
28-
var books =
29-
SelectionSpecification.create(Book.class,
30-
"from Book where discontinued = false")
31-
.restrict(Restriction.startsWith(Book_.title, "hibernate"))
32-
.sort(Order.desc(Book_.title))
33-
.fetch(Path.from(Book.class).to(Book_publisher))
34-
.createQuery(session)
35-
.setPage(Page.first(50))
36-
.getResultList();
37-
----
38-
39-
==== Support for Jakarta Data ====
24+
==== Support for Jakarta Data
4025
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 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.:
4126

4227
[source,xml]
@@ -69,27 +54,65 @@ public interface Library {
6954

7055
This topic deserves a deeper dive, so let us know if you're interested, as we could provide more content.
7156

72-
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.
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.
7358

74-
=== Hibernate Reactive together with Hibernate ORM ===
7559

76-
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.24, it is now possible to mix the two.
60+
==== New Restrictions API
61+
After the deprecation of the 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 query using JPQL/HQL.
62+
63+
[source,text]
64+
----
65+
var 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+
.fetch(Path.from(Book.class).to(Book_publisher))
73+
.createQuery(session)
74+
.setPage(Page.first(50))
75+
.getResultList();
76+
----
77+
78+
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:
79+
80+
```java
81+
@Find
82+
List<Book> books(Restriction<Book> restriction,
83+
Order<Book> order);
84+
```
85+
86+
When user will call the method, they can pass the `Restriction` objects to filter the wanted book.
87+
88+
```java
89+
var books =
90+
library.books(Restriction.contains(Book_.title, "Hibernate"),
91+
Order.of(_Book.title.ascIgnoreCase(),
92+
_Book.isbn.asc()));
93+
```
94+
95+
=== Hibernate Reactive together with Hibernate ORM
96+
97+
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 is now possible to mix the two.
98+
7799
Hibernate Reactive is a powerful reactive data access abstraction, but its advantages vary per project. Instead of dictating usage, we 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, running 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.
100+
78101
Panache users will have this possibility in the API as well starting from https://github.com/quarkusio/quarkus/issues/46096[Panache 2.0]
79102

80-
=== Injection of the SchemaManager ===
103+
=== Injection of the SchemaManager
81104

82-
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 a simple injection. This is particularly useful when writing tests letting you programmatically control when to do schema export, schema validation, data cleanup, and schema cleanup.
105+
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 a simple 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.
83106

84-
=== The Future ===
107+
=== The Future
85108

86109
The teams have many plans for the future of the 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]
87110

88111
image::console.gif[scaledwidth=100%]
89112

90113
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].
91114

92-
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 `IdentityHasMap` 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+
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.
93116
And that's just _one_ improvement among many, and not the last one: even bigger performance improvements are expected in the future.
94117

95118
https://quarkus.io/guides/update-quarkus[Take a look at the new release] and let us know what you think!

0 commit comments

Comments
 (0)