Allow using both of Hibernate Reactive's CDI-injected Session and StatelessSession in the same transaction when using @Transactional#53509
Conversation
|
/cc @gsmet (hibernate-orm) |
|
🙈 The PR is closed and the preview is expired. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
lucamolteni
left a comment
There was a problem hiding this comment.
Glad to hear it (somehow) worked already :)
gsmet
left a comment
There was a problem hiding this comment.
I added a small suggestion but feel free to merge if you don't think it has value.
…sSession This test confirms that blocking Hibernate ORM already allows using both regular Session and StatelessSession within the same transaction. Both session types can be used together, and changes from both are properly committed or rolled back together. This serves as a reference implementation before enabling the same capability in Hibernate Reactive. Assisted-By: Claude Code <noreply@anthropic.com>
… package Because that's the convention for classes that are not API. Technically this should be SPI, but since for now we only intend to use these classes in the core Quarkus project, this will do.
…eactive-transactions Moved TransactionalContextPool and TransactionalContextConnection from hibernate-reactive to reactive-transactions module, as they are not specific to Hibernate Reactive and are used by the transaction interceptors. Additionally, introduced getCurrentConnectionFromVertxContext() method in TransactionalContextPool for consistent access to the current connection from the Vert.x context. Assisted-By: Claude Code <noreply@anthropic.com>
…action This change removes the artificial restriction that prevented using both Mutiny.Session and Mutiny.StatelessSession within the same @transactional method in Hibernate Reactive, bringing it in line with blocking Hibernate ORM. Key changes: - Added thread-safe connection reuse in TransactionalContextPool: when a second session type requests a connection within the same transaction, it reuses the existing connection from the Vert.x context. Uses VarHandle with compareAndSet to prevent race conditions when both session types request connections concurrently. - Extracted ConnectionHolder as a package-protected class that ensures only one connection is created per transaction even with concurrent access, using a Promise pattern inspired by Hibernate Reactive's ProxyConnection - Made TransactionalContextConnection.close() a no-op to prevent premature connection closure, letting only TransactionalInterceptorBase close the actual connection at transaction end - Changed TransactionalContextPool.getCurrentConnectionFromVertxContext() to return a Future instead of the connection directly, allowing callers to handle async connection availability - Updated TransactionalInterceptorBase.connectionFromContext() to return Uni<SqlConnection> and all its callers to handle null checks before converting to Uni - Updated TransactionalInterceptorBase to use TransactionalContextPool.closeAndClearCurrentConnection() to properly close the connection and clear it from the Vert.x context - Removed validation checks in HibernateReactiveRecorder that threw IllegalStateException when mixing session types - Transformed MixStatelessStatefulSessionTest from negative (expecting failures) to positive tests verifying both session types work together, share connections, and commit/rollback together - Updated documentation to explain that mixing is now supported and both session types share the same underlying connection Both session types can now coexist in the same transaction, using the appropriate session type for different operations (e.g., StatelessSession for bulk operations, regular Session for operations requiring caching). Fixes quarkusio#52828 Assisted-By: Claude Code <noreply@anthropic.com>
This comment has been minimized.
This comment has been minimized.
Status for workflow
|
Status for workflow
|
See commit messages for details.