Skip to content

Forbid/discourage connecting to a database through Hibernate using both blocking and reactive in the same transaction scope #46756

@yrodiere

Description

@yrodiere

Description

Panache 2 (#46096) will make it (much) easier to switch from different paradigms to connect to databases through Hibernate: Session vs. StatelessSession, JDBC vs. reactive, ...

That's great, and is perfectly fine if you pick a single one of these options in each transaction, but can be dodgy if you use more than one of these options in a single transaction.

Here's the current situation as far as I know:

  1. When in a (JTA) transaction and using Hibernate ORM, using both a Session and StatelessSession in the same transaction is fine (I told you the opposite @FroMage: I was wrong): the JDBC connection is shared at the Agroal level, and all connection requests during a single JTA transaction yield the same connection, so the Session and StatelessSession will just share their connection, and thus the same DB transaction.
  2. When using Hibernate Reactive, using both a Session and StatelessSession in the same transaction is probably not fine at all: I suspect each will leverage an independent transaction. Conflicting updates will yield transaction rollbacks, and worse: rollback in one of the transactions will not trigger a rollback in the other one, leading to inconsistency in the DB. => It's fine now, see Hibernate Reactive: allow mixing Session and StatelessSession in the same transaction #52828
  3. When using both Hibernate ORM and Hibernate Reactive in the same endpoint, ORM will enroll in a JTA transaction but Reactive will not: it will use non-JTA transactions. Conflicting updates will yield transaction rollbacks, and worse: rollback in one of the transactions will not trigger a rollback in the other one, leading to inconsistency in the DB.

I think we need to address this: at the very least document limitations, and perhaps even forbid using Hibernate Reactive and Hibernate ORM in the same endpoint, or forbid having a blocking (JTA) and reactive transaction scope active at the same time.

Implementation ideas

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions