Skip to content

Conversation

lucamolteni
Copy link
Contributor

@lucamolteni lucamolteni commented Sep 16, 2025

  • Integration test for multiple reactive persistence units and Panache
  • Backported from ORM the handling of different persistence units in entity in Panache
  • withSession overload to take the PU name
  • Added Panache.withTransaction overload to select persistence unit
  • Execute update without entity runs on default session
  • 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
  • Updated Panache documentation

Release Notes: Hibernate Reactive Panache Enhancements

Complete support for multiple persistence units in Hibernate Reactive Panache, bringing feature parity with Hibernate ORM
Panache.

New API Methods:

// Specify persistence unit for sessions
@WithSession("secondary")

or

Panache.withSession("secondary", () -> { ... })

// Specify persistence unit for transactions  
@WithTransaction("secondary")

or

Panache.withTransaction("secondary", () -> { ... })

// Repository operations work with entity's configured PU
secondaryRepository.findAll() // Uses "secondary" PU automatically

Kotlin Module Independence

The Hibernate Reactive Panache Kotlin module has been changed to depend only on the hibernate-reactive-panache-common module, aligning it to the ORM version.
Backwards compatibility is maintained through a copy of Panache class inside the Kotlin module

// New primary class for Kotlin users
io.quarkus.hibernate.reactive.panache.kotlin.Panache

// Deprecated compatibility class  
io.quarkus.hibernate.reactive.panache.Panache // @Deprecated

The copied class will be eventually removed

Fixes this reproducer reported by a user

@lucamolteni lucamolteni changed the title [DRAFT] Panache Support multiple persistence unit in Hibernate Reactive DRAFT Panache Support multiple persistence unit in Hibernate Reactive Sep 16, 2025
Copy link
Member

@FroMage FroMage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Answered inline

@lucamolteni lucamolteni force-pushed the reproducer-multiple branch 2 times, most recently from 577434e to 500587e Compare September 30, 2025 09:44
@lucamolteni
Copy link
Contributor Author

I've tackled most of the comments and the current tests are passing

I still need to add a few more test for the named persistence unit overload

Copy link

github-actions bot commented Sep 30, 2025

🙈 The PR is closed and the preview is expired.

@lucamolteni lucamolteni force-pushed the reproducer-multiple branch 2 times, most recently from 99cd94a to 74882ef Compare October 1, 2025 08:59
@lucamolteni lucamolteni marked this pull request as ready for review October 1, 2025 08:59
@lucamolteni lucamolteni changed the title DRAFT Panache Support multiple persistence unit in Hibernate Reactive Panache Support multiple persistence unit in Hibernate Reactive Oct 1, 2025
@lucamolteni
Copy link
Contributor Author

setting "ready for review" as I need CI

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

@lucamolteni
Copy link
Contributor Author

Tests are passing now! I think it can be reviewed now

@lucamolteni
Copy link
Contributor Author

@FroMage thanks to @yrodiere today I managed to do this I think it should be what you were thinking about, please take a look

@FroMage
Copy link
Member

FroMage commented Oct 13, 2025

Anyway... as far as I can see @lucamolteni didn't change the keys themselves, so it should still work fine?

Well, depends, if on our end we set the value to be a List (of sessions) while on the HR side they expect the value to be a single session, things will break.

@yrodiere
Copy link
Member

Anyway... as far as I can see @lucamolteni didn't change the keys themselves, so it should still work fine?

Well, depends, if on our end we set the value to be a List (of sessions) while on the HR side they expect the value to be a single session, things will break.

AFAIU the things we changed that way are strictly Panache-specific: https://github.com/quarkusio/quarkus/pull/50084/files#diff-22c7ded8d8a11870b590c9c653f8884dffad2727677e07d2c306fb99b48726ebR65-R68

The important one, shared with Hibernate Reactive, didn't change in such a way.

But anyway, tests will tell.

@lucamolteni
Copy link
Contributor Author

That's... an odd choice, because it effectively means withSession:

  1. Has a very different behavior than org.hibernate.SessionFactory#inSession, which always opens a new session.
  2. Cannot be used to force opening a new session.

Anyway... as far as I can see @lucamolteni didn't change the keys themselves, so it should still work fine?

I would suggest adding a test specifically for this (hidden) feature if there isn't one already, checking that sessionFactory.withSession(...) will reuse the session opened by @WithSession/@WithSessionOnDemande, and vice-versa?

Then we're good to merge.

See #50532

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

Copy link
Member

@yrodiere yrodiere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's one very suspicious test, but if you're sure of what you're doing...

@yrodiere yrodiere dismissed their stale review October 15, 2025 11:17

Addressed

@FroMage
Copy link
Member

FroMage commented Oct 15, 2025

So, do we merge this? I can start rebasing Panache 2 on this then.

@lucamolteni
Copy link
Contributor Author

So, do we merge this? I can start rebasing Panache 2 on this then.

Updated the test and rebased

This comment has been minimized.

This comment has been minimized.

* 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 link

quarkus-bot bot commented Oct 15, 2025

Status for workflow Quarkus Documentation CI

This is the status report for running Quarkus Documentation CI on commit 26e8896.

✅ The latest workflow run for the pull request has completed successfully.

It should be safe to merge provided you have a look at the other checks in the summary.

Warning

There are other workflow runs running, you probably need to wait for their status before merging.

Copy link

quarkus-bot bot commented Oct 15, 2025

Status for workflow Quarkus CI

This is the status report for running Quarkus CI on commit 26e8896.

✅ The latest workflow run for the pull request has completed successfully.

It should be safe to merge provided you have a look at the other checks in the summary.

You can consult the Develocity build scans.


Flaky tests - Develocity

⚙️ Gradle Tests - JDK 17 Windows

📦 integration-tests/gradle

io.quarkus.gradle.devmode.IncludedKotlinBuildDevModeTest.main - History

  • Condition with Lambda expression in io.quarkus.test.devmode.util.DevModeClient was not fulfilled within 1 minutes 30 seconds. - org.awaitility.core.ConditionTimeoutException
org.awaitility.core.ConditionTimeoutException: Condition with Lambda expression in io.quarkus.test.devmode.util.DevModeClient was not fulfilled within 1 minutes  30 seconds.
	at org.awaitility.core.ConditionAwaiter.await(ConditionAwaiter.java:167)
	at org.awaitility.core.CallableCondition.await(CallableCondition.java:78)
	at org.awaitility.core.CallableCondition.await(CallableCondition.java:26)
	at org.awaitility.core.ConditionFactory.until(ConditionFactory.java:1160)
	at org.awaitility.core.ConditionFactory.until(ConditionFactory.java:1129)
	at io.quarkus.test.devmode.util.DevModeClient.getHttpResponse(DevModeClient.java:164)
	at io.quarkus.gradle.devmode.QuarkusDevGradleTestBase.getHttpResponse(QuarkusDevGradleTestBase.java:165)

@yrodiere yrodiere merged commit 44ec5f4 into quarkusio:main Oct 15, 2025
33 checks passed
@quarkus-bot quarkus-bot bot added this to the 3.29 - main milestone Oct 15, 2025
@quarkus-bot quarkus-bot bot added the kind/enhancement New feature or request label Oct 15, 2025
@FroMage
Copy link
Member

FroMage commented Oct 16, 2025

Yay! 🥳

@yrodiere
Copy link
Member

yrodiere commented Oct 16, 2025

Congrats @lucamolteni :)

@gsmet , oddly the bot assigned milestone 3.29.0.CR1 to this PR. I merged it yesterday evening, so I would have expected 3.30.something... ?

Did you postpone the release? If so we will need to update the @Deprecated(since = ...) in this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for multiple persistence units in Hibernate Reactive with Panache

4 participants