-
-
Notifications
You must be signed in to change notification settings - Fork 102
Description
In Quarkus PR #51063 (Support @transactional for Hibernate Reactive, addressing #47698), we implemented
automatic transaction management by opening transactions in TransactionalContextPool.getConnection():
@Override
public Future<SqlConnection> getConnection() {
if (!shouldOpenTransaction()) {
return delegate.getConnection();
} else {
return delegate.getConnection()
.compose(connection -> {
return connection.begin().map(t -> {
Transaction transaction = connection.transaction();
Vertx.currentContext().putLocal(CURRENT_TRANSACTION_KEY, transaction);
return new TransactionalContextConnection(connection);
});
});
}
}While the transaction is started and stored in the Vert.x context, Hibernate Reactive's
Mutiny.Session#currentTransaction field is never updated. This means that calling
session.currentTransaction() returns null even though a transaction is active.
As noted by @yrodiere:
If we open transactions "under the hood", we will need Hibernate Reactive to correctly detect that and
expose Mutiny.Session#currentTransaction accordingly.
Expected Behavior:
There should be a way in Hibernate Reactive to fix state so that wen a transaction is opened by TransactionalContextPool, Mutiny.Session#currentTransaction() should
return the active transaction.
Actual Behavior:
Mutiny.Session#currentTransaction() returns null because the session's internal currentTransaction
field is not updated when the transaction is opened at the connection pool level.
Impact:
- Code that relies on session.currentTransaction() to check if a transaction is active will not work
correctly - Transaction state is not visible through the Hibernate Reactive API