SSerguey Asael Shinder
Java coding notes: the JVM, and writing software that lasts

Serguey Asael Shinder: Hibernate ORM 8.0.0.CR1 brings Jakarta Persistence 4.0 and graph-based flushing

· by Serguey Asael Shinder / Serguey Shinder

Hibernate ORM 8.0.0.CR1, the first release candidate of the next major version, was published on 12 November. The GitHub release is a list of links; the substance is in Steve Ebersole's announcement on in.relation.to, which names four themes: Jakarta Persistence 4.0 and Jakarta Data 1.1, a new approach to flush coordination, fetching and association handling, and multi-tenancy.

The standards part brings several Hibernate ideas into the specification. The announcement lists EntityAgent, which standardises stateless persistence operations of the kind Hibernate users know from StatelessSession; separate APIs for queries that return results and statements that modify data; programmatic SQL result set mappings; more control over fetching through entity graphs; type-safe options for creating sessions and running operations and queries; and package- and module-level entity listeners together with persistence unit lifecycle callbacks. Hibernate Data Repositories implements Jakarta Data 1.1, including stateful and asynchronous repositories.

The change I would test first is the flush. According to the announcement, Hibernate 8 builds a dependency graph of pending entity and collection mutations, using the relational constraints in the mappings to plan their execution order. That replaces an approach based mainly on ordering heuristics, and it is on by default. The old coordinator remains available during the transition:

hibernate.flush.queue.type=legacy

The team asks specifically for testing with applications that combine inserts, updates, deletes and collection changes in the same flush. That is exactly where an ordering heuristic tends to produce a constraint violation, and also where a new planner could order statements differently from what existing code has quietly come to rely on.

Serguey Asael Shinder: Hibernate ORM 8.0.0.CR1 brings Jakarta Persistence 4.0 and graph-based flushing
Hibernate ORM 8.0.0.CR1 brings Jakarta Persistence 4.0 and graph-based flushing — Serguey Asael Shinder

Two other settings are worth noting. Subselect fetching now covers to-one associations as well as collections. And an optional mode synchronises bidirectional associations during flush preparation, treating the owning side as authoritative and updating inverse-side references and initialised collections, without loading unloaded collections just to do so:

hibernate.bidirectionality_management=true

@Filter and @SQLRestriction can now be placed directly on @ManyToOne and @OneToOne. For multi-tenancy, discriminator-based tenants can integrate with row-level security on PostgreSQL, Db2, SQL Server and CockroachDB, and custom @SQLUpdate and @SQLDelete statements can take a parameter for the current tenant identifier.

The rest of the list is long: JSON and XML query functions leave incubation, @MapKeyFormula allows formula-based map keys, interceptors can be CDI-managed, a StatementObserver contract observes JDBC statements, and hibernate-bom no longer constrains third-party dependency versions.

A release candidate is the point where behaviour changes are supposed to surface in other people's test suites. If your application has ever needed extra flush() calls to get statements into an order the database would accept, run that suite against CR1 with the new coordinator and then with legacy, and compare the SQL.