Skip to content

ADR-0095: Opt-in Hibernate Reactive stateless persistence provider for the persistence plugin ​

Context ​

TPF's foundational persistence plugin records domain step outputs across configured aspect boundaries (typically AFTER_STEP side effects) without changing pipeline business semantics. Its default reactive driver (ReactivePanachePersistenceProvider / PersistenceService in pipelineframework-runtime) relies on a managed Hibernate Reactive Mutiny.Session backed by Vert.x duplicated contexts and VertxContextSafetyToggle.

In high-throughput streaming pipelines (ONE_TO_MANY and MANY_TO_MANY), a managed persistence context adds overhead that the persistence aspect rarely needs:

  1. Every persisted step output is tracked in a first-level session cache for dirty-checking and lazy-loading proxies, even though TPF persistence side effects typically write self-contained snapshots.
  2. Keeping ReactivePanachePersistenceProvider as the default preserves full backwards compatibility for existing applications whose entities rely on JPA CascadeType or managed session behaviour, while applications persisting flat or self-contained snapshots benefit from an explicit stateless reactive provider.
  3. On Quarkus 4, quarkus-hibernate-reactive ships Hibernate Reactive 5 (5.1.0.CR3 in Quarkus 4.0.1) with native Mutiny.SessionFactory.withStatelessTransaction and Mutiny.StatelessSession support directly on the reactive persistence stack, avoiding any need to pull blocking quarkus-hibernate-orm / quarkus-data-hibernate runtime dependencies into persistence-plugin.

At the same time, ADR-0008 keeps aspect persistence distinct from durable control-plane stores (Command effects, Query capture, Await state, and execution state), and existing applications whose entities depend on JPA cascade graphs or dirty-checking continue to use the default managed-session path.

Decision ​

The Quarkus 4 foundational persistence plugin in pipelineframework-runtime provides an opt-in stateless reactive persistence provider (StatelessReactivePersistenceProvider) backed directly by Hibernate Reactive 5 Mutiny.SessionFactory.withStatelessTransaction / Mutiny.StatelessSession, while retaining ReactivePanachePersistenceProvider as the default when unconfigured.

1. Explicit stateless semantics without pulling blocking ORM dependencies ​

  • StatelessReactivePersistenceProvider resolves Mutiny.SessionFactory lazily from Quarkus ArC and executes writes inside sessionFactory.withStatelessTransaction(...) using session.insert(entity) for persist(...) and session.upsert(entity) for persistOrUpdate(...) on a duplicated Vert.x context without first-level cache retention, dirty-checking, or implicit JPA relationship cascades.
  • persistence-plugin stays strictly reactive and does not pull blocking quarkus-hibernate-orm into reactive-only service modules.
  • Failure rollback, duplicate/conflict surfacing, and transaction boundaries remain explicit and reactive without blocking Vert.x event-loop threads.
  • This decision governs the foundational persistence plugin only. Durable control-plane stores (ADR-0018, ADR-0020, ADR-0044, ADR-0045, ADR-0046) and Hibernate find.many Query providers (ADR-0022) retain their own separate contracts and authorities.

2. Dual-surface provider selection stays unchanged ​

  • Applications select the active persistence provider through both aligned surfaces:
    • runtime configuration: persistence.provider.class=org.pipelineframework.plugin.persistence.provider.StatelessReactivePersistenceProvider
    • build-time compiler option: -Apersistence.provider.class=org.pipelineframework.plugin.persistence.provider.StatelessReactivePersistenceProvider
  • Applications that do not set persistence.provider.class continue to resolve the default ReactivePanachePersistenceProvider with full JPA cascade and managed-session semantics.

3. Upstream Hibernate Final tracking ​

  • Because quarkus-bom:4.0.1 ships pre-Final Hibernate CR artefacts (hibernate-core:8.0.0.CR2 and hibernate-reactive-core:5.1.0.CR3), TPF tracks upstream Hibernate ORM 8 / Hibernate Reactive 5.1 Final alignment in a subsequent Quarkus 4.0.x patch release.

Rationale ​

  • Natural match for immutable pipeline persistence: Persisting step outputs in an AFTER_STEP aspect is an append/upsert-style projection, not an ORM unit-of-work graph mutation. Removing first-level cache retention prevents unbounded session memory growth during ONE_TO_MANY streams.
  • No blocking ORM creep: Using Mutiny.SessionFactory.withStatelessTransaction directly keeps persistence-plugin free of blocking quarkus-hibernate-orm transitive dependencies.
  • Zero-surprise migration: Keeping ReactivePanachePersistenceProvider as the default prevents silent breakage for existing JPA entity graphs that require cascades, while giving streaming applications an opt-in switch configured consistently via persistence.provider.class and -Apersistence.provider.class.

Consequences ​

  • pipelineframework-runtime: Ships StatelessReactivePersistenceProvider alongside ReactivePanachePersistenceProvider in persistence-plugin, verified by StatelessReactivePersistenceProviderTest covering entity validation, stateless transaction upsert, rollback/conflict propagation, and dual-surface provider selection.
  • pipelineframework: Documents provider selection in Using plugins and records migration evidence in Quarkus 4.0 migration.
  • Applications & reference implementations: Applications persisting flat or self-contained records can opt in via persistence.provider.class / -Apersistence.provider.class; existing applications relying on JPA cascades retain unchanged default behaviour.

Diagram