You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Panache Support multiple persistence unit in Hibernate Reactive
* Integration test for multiple reactive persistence units and Panache
Backported from ORM the handling of different persistence units in entity in Panache
* `@WithSessionOnDemand` works only with the default persistence unit
* withSession overload to take the PU name
* Execute update without entity runs on default session
* Repository flush() flushes all PUs
Refactor
* Use ComputingCache instead of a Map<String, LazyValue>
* Keep track of onDemand created sessions to close them accordingly
* create map of entity => PU in kotlin as well (identical to what happens in Hibernate ORM)
* Aligned reactive blocking to orm repositories by using @GenerateBridge to call getSession
* getSession shouldn't be static to be substituted by @GenerateBridge
* Added Panache.withTransaction overload to select persistence unit
* Updated Panache documentation
* Support @WithSession("pu-name") and @WithTransaction("pu-name")
* Added test to verify the same session is used
* Removed dependency from Kotlin panache module to Java, created two new Panache classes inside the Kotlin module and changed the tests accordingly.
Copy file name to clipboardExpand all lines: docs/src/main/asciidoc/hibernate-reactive-panache.adoc
+6-1Lines changed: 6 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -772,7 +772,10 @@ If no annotations are found.
772
772
773
773
== Multiple Persistence Units
774
774
775
-
Hibernate Reactive in Quarkus currently does not support multiple persistence units.
775
+
Hibernate Reactive with Panache supports multiple persistence units.
776
+
When using multiple persistence units, Panache automatically uses the correct persistence unit based on the entity's configuration.
777
+
778
+
For configuration details on setting up multiple persistence units, refer to the xref:hibernate-orm.adoc#multiple-persistence-units[Multiple Persistence Units] section in the Hibernate ORM guide.
776
779
777
780
[[transactions]]
778
781
== Sessions and Transactions
@@ -783,13 +786,15 @@ For example, if a Panache entity method is invoked in a Jakarta REST resource me
783
786
For other cases, there are both a declarative and a programmatic way to ensure the session is opened.
784
787
You can annotate a CDI business method that returns `Uni` with the `@WithSession` annotation.
785
788
The method will be intercepted and the returned `Uni` will be triggered within a scope of a reactive session.
789
+
If you have multiple persistence units, you can specify which one to use by providing the persistence unit name as the annotation value: `@WithSession("my-persistence-unit")`. If not specified, the default persistence unit is used.
786
790
Alternatively, you can use the `Panache.withSession()` method to achieve the same effect.
787
791
788
792
NOTE: Note that a Panache entity may not be used from a blocking thread. See also xref:getting-started-reactive.adoc[Getting Started With Reactive] guide that explains the basics of reactive principles in Quarkus.
789
793
790
794
Also make sure to wrap methods that modify the database or involve multiple queries (e.g. `entity.persist()`) within a transaction.
791
795
You can annotate a CDI business method that returns `Uni` with the `@WithTransaction` annotation.
792
796
The method will be intercepted and the returned `Uni` is triggered within a transaction boundary.
797
+
If you have multiple persistence units, you can specify which one to use by providing the persistence unit name as the annotation value: `@WithTransaction("my-persistence-unit")`. If not specified, the default persistence unit is used.
793
798
Alternatively, you can use the `Panache.withTransaction()` method for the same effect.
794
799
795
800
IMPORTANT: You cannot use the `@Transactional` annotation with Hibernate Reactive for your transactions: you must use `@WithTransaction`, and your annotated method must return a `Uni` to be non-blocking.
Copy file name to clipboardExpand all lines: extensions/panache/hibernate-reactive-panache-common/runtime/src/main/java/io/quarkus/hibernate/reactive/panache/common/WithSession.java
Copy file name to clipboardExpand all lines: extensions/panache/hibernate-reactive-panache-common/runtime/src/main/java/io/quarkus/hibernate/reactive/panache/common/WithTransaction.java
Copy file name to clipboardExpand all lines: extensions/panache/hibernate-reactive-panache-common/runtime/src/main/java/io/quarkus/hibernate/reactive/panache/common/runtime/AbstractJpaOperations.java
0 commit comments