liveBook · Manning

QuarkusTransaction

As explained in Quarkus in Action

QuarkusTransaction is a Quarkus API for programmatic transaction management with static operations and transactional code wrappers.

QuarkusTransaction provides programmatic transaction management through static operations and wrappers for transactional Runnable or Callable code. It helps keep transaction boundaries explicit when work runs outside a CDI method, such as a gRPC stream callback. section 7.5.2 section 7.2.2

Use the API in two complementary ways:

  • Call begin(), commit(), and rollback() directly, optionally configuring begin options such as a timeout. section 7.5.2
  • Wrap work with requiringNew(), joiningExisting(), disallowingExisting(), or suspendingExisting() to select transaction semantics. section 7.5.2
  • Configure wrapper timeouts and exception handlers that can choose whether certain failures still commit or cause rollback. section 7.5.2

One transaction per streamed car

A gRPC service can wrap each repository persist operation with QuarkusTransaction.requiringNew().run(() -> { carRepository.persist(car); });. This commits each car separately instead of keeping one transaction open for the entire stream, avoiding a long-lived transaction and possible timeout. section 7.2.2

Listing 7.25 Transaction wrappers provided by QuarkusTransaction
QuarkusTransaction.requiringNew().run(() -> {      #1
    // perform operation
});

var txResult = QuarkusTransaction.joiningExisting()
    .timeout(30)
    .exceptionHandler(throwable -> {
        if (throwable instanceof AnyRecoverableException) {
            return TransactionExceptionResult.COMMIT;
        }
        return TransactionExceptionResult.ROLLBACK;
    }).call(() -> {                                     #2
        var result = // perform operation
        return result;
    });

The wrapper example combines transaction selection, a timeout, an exception handler, and a Callable result. section 7.5.2

How Quarkus in Action covers it

How deep it goes
Explains static lifecycle calls, Runnable and Callable wrappers, propagation semantics, timeouts, and exception-based commit decisions.
Examples
Demonstrates manual begin/commit/rollback, configurable wrappers, and per-car persistence in a gRPC inventory stream.
What it assumes
Builds from JTA UserTransaction and CDI bean injection before introducing QuarkusTransaction's static and fluent APIs.
What you can do after
Apply it via QuarkusTransaction to choose transaction boundaries, configure behavior, and handle persistence failures programmatically.
How it connects
Connects transaction management with JTA UserTransaction, CDI beans, repository persistence, gRPC streaming, and blocking database work.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Quarkus in Action. The section links point to the parts of the book it draws on.