Skip to content

Mutiny.Session#currentTransaction not updated when transaction is opened by TransactionalContextPool #2852

@lucamolteni

Description

@lucamolteni

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions