Skip to content

clarify some stuff about session mgt with reactive repositories #10062

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ Hibernate Processor defaults to using `EntityManager` as the session type, but o

- `Session`,
- `StatelessSession`, or
- `Mutiny.Session` from Hibernate Reactive.
- `Mutiny.Session` or `Mutiny.StatelessSession` from Hibernate Reactive.

The real value of all this is in the checks which can now be done at compile time.
Hibernate Processor verifies that the parameters of our abstract method declaration match the parameters of the HQL query, for example:
Expand Down
12 changes: 10 additions & 2 deletions documentation/src/main/asciidoc/repositories/Reactive.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ interface Library {

It's _not_ possible to mix blocking and non-blocking operations in the same repository interface.

IMPORTANT: Depending on how you're managing the stateless session, you might need to declare the resource accessor method with the type `Uni<Mutiny.StatelessSession>`.

=== Obtaining a reactive repository

To make use of our reactive repository, we'll need to bootstrap Hibernate Reactive and obtain a `Mutiny.SessionFactory`.
Expand All @@ -61,7 +63,9 @@ Mutiny.SessionFactory factory =
.unwrap(Mutiny.SessionFactory.class);
----

Please refer to the documentation for Hibernate Reactive for more information on this topic.
Please refer to the https://hibernate.org/reactive/documentation/[documentation for Hibernate Reactive] for more information on this topic.

TIP: In Quarkus, this step is unnecessary, and you can let Quarkus manage and inject the reactive `SessionFactory`.

Once we have the `SessionFactory`, we can easily obtain a `Mutiny.StatelessSession`, and use it to instantiate our repository:

Expand All @@ -73,7 +77,11 @@ factory.withStatelessTransaction(session -> {
})
----

TIP: In Quarkus, all this is unnecessary, and you can directly inject the `Library`.
TIP: An even better approach is to make a `@RequestScoped` instance of `Mutiny.StatelessSession` or `Uni<Mutiny.StatelessSession>` available for injection by CDI.
Then the `Library` repository itself may be directly injected, and you won't have to worry about managing the stateless session in application program code.
This is a little bit tricky to get working perfectly, so hopefully by the time you're reading this, there will already be a built-in implementation in Quarkus.

// TIP: In Quarkus, all this is unnecessary, and you can directly inject the `Library`.

=== Calling a reactive repository

Expand Down