Skip to content

Commit abdffb4

Browse files
committed
clarify some stuff about session mgt with reactive repositories
1 parent 1027693 commit abdffb4

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

documentation/src/main/asciidoc/introduction/Processor.adoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ Hibernate Processor defaults to using `EntityManager` as the session type, but o
304304

305305
- `Session`,
306306
- `StatelessSession`, or
307-
- `Mutiny.Session` from Hibernate Reactive.
307+
- `Mutiny.Session` or `Mutiny.StatelessSession` from Hibernate Reactive.
308308

309309
The real value of all this is in the checks which can now be done at compile time.
310310
Hibernate Processor verifies that the parameters of our abstract method declaration match the parameters of the HQL query, for example:

documentation/src/main/asciidoc/repositories/Reactive.adoc

+10-2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ interface Library {
4949

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

52+
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>`.
53+
5254
=== Obtaining a reactive repository
5355

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

64-
Please refer to the documentation for Hibernate Reactive for more information on this topic.
66+
Please refer to the https://hibernate.org/reactive/documentation/[documentation for Hibernate Reactive] for more information on this topic.
67+
68+
TIP: In Quarkus, this step is unnecessary, and you can let Quarkus manage and inject the reactive `SessionFactory`.
6569

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

@@ -73,7 +77,11 @@ factory.withStatelessTransaction(session -> {
7377
})
7478
----
7579

76-
TIP: In Quarkus, all this is unnecessary, and you can directly inject the `Library`.
80+
TIP: An even better approach is to make a `@RequestScoped` instance of `Mutiny.StatelessSession` or `Uni<Mutiny.StatelessSession>` available for injection by CDI.
81+
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.
82+
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.
83+
84+
// TIP: In Quarkus, all this is unnecessary, and you can directly inject the `Library`.
7785

7886
=== Calling a reactive repository
7987

0 commit comments

Comments
 (0)