https://zbciok.github.io/docs/smallrye-mutiny/implementations/hibernate-reactive
https://hibernate.org/reactive/
Reactive Object/Relational Mapping
Hibernate Reactive is a reactive API for Hibernate ORM, supporting non-blocking database drivers and a reactive style of interaction with the database.
Hibernate Reactive is intended for use in a reactive programming environment like Vert.x or Quarkus, where interaction with the database should occur in a non-blocking fashion. Persistence operations are orchestrated via the construction of a reactive stream rather than via direct invocation of synchronous functions in procedural Java code.
JDBC, JPA and Hibernate ORM use blocking IO for interaction with the database, and are therefore not appropriate for use in a reactive environment. Hibernate Reactive is a feature rich ORM implementation designed to take advantage of non-blocking database clients.
Compatibility
Hibernate Reactive requires:
- Java 11,
- Hibernate ORM 6.2, and
- the Vert.x 4.4 reactive database client for your database.
It works with PostgreSQL, MySQL, MariaDB, Db2, SQL Server, Oracle and CockroachDB.
Getting Started
The Introduction to Hibernate Reactive covers everything you need to know to get started, including:
- setting up a project that uses Hibernate Reactive and the Vert.x reactive SQL client for your database,
- configuring Hibernate Reactive to access your database,
- writing Java code to define the entities of your data model,
- writing reactive data access code using a reactive session, and
- tuning the performance of your program.
Reactive Session
https://zbciok.github.io/docs/smallrye-mutiny/implementations/hibernate-reactive
The reactive Session is available in two flavours: the Stage.Session which uses Java’s CompletionStage as the async type, and a Mutiny.Session, which uses Red Hat’s Mutiny asynchronous type Uni.
Stage.Sessionand friends provide a reactive API based around Java’sCompletionStage, andMutiny.Sessionand friends provide an API based on Mutiny.
These are the most important operations on reactive streams that you’ll need all the time when working with Hibernate Reactive:
| Purpose | Java CompletionStage | Mutiny Uni |
|---|---|---|
| Chain non-blocking operations | thenCompose() | chain() |
| Transform streamed items | thenApply() | map() and replaceWith() |
| Perform an action using streamed items | thenAccept() | invoke() and call() |
Perform cleanup (similar to finally) | whenComplete() | eventually() |
When we use the term reactive stream in this document, we mean:
- a chain of
CompletionStages, or - a chain of Mutiny
Unis andMultis
that is built by the program in order to service a particular request, transaction, or unit of work.
