liveBook · Manning

@WithTransaction

As explained in Quarkus in Action

@WithTransaction is an annotation that defines a transaction boundary for an asynchronous Hibernate Reactive operation.

@WithTransaction defines the transaction boundary for an asynchronous Hibernate Reactive operation. Applied to a method returning Uni, it provides the reactive equivalent of @Transactional: the transaction commits only after the asynchronous result becomes available. section 7.7.2

Use it when a REST endpoint persists data through Hibernate Reactive. The surrounding method must propagate its Uni result, and work inside the pipeline must remain nonblocking, including outgoing reactive service calls. section 7.7.2

Reservation creation

Annotate ReservationResource#make with @WithTransaction and return reservation.persist(). The persistence callback can start a rental through a Uni-returning client, then replace that result with the persisted reservation. section 7.7.2

How Quarkus in Action covers it

How deep it goes
Explains asynchronous commit behavior and method-level application, while deferring broader reactive programming analysis.
Examples
Uses ReservationResource#make to persist a reservation and start a rental through a reactive client.
What it assumes
Assumes familiarity with Uni and reactive endpoints while introducing their role in transaction timing.
What you can do after
Apply it via Hibernate Reactive to commit database work after a Uni pipeline completes.
How it connects
Connects Hibernate Reactive, Uni, Hibernate ORM transactions, Quarkus REST, and nonblocking service clients.

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.