Skip to content

@JoinColumns breaks on Hibernate Reactive #45188

Description

@LarsSven

Describe the bug

If you write an entity like the following:

@Entity
class ExampleParentEntity(
    @field:ManyToOne(fetch = FetchType.EAGER)
    @field:JoinColumns(
        value = [
            JoinColumn(name = "id", referencedColumnName = "id"),
            JoinColumn(name = "revision", referencedColumnName = "revision")
        ]
    )
    var child: ExampleEntity = ExampleEntity(),

    @Id
    var parentId: UUID = UUID.randomUUID(),
)

And then try to retrieve it from the database when using Hibernate Reactive, your program crashes with a rather vague exception (and no usable stacktrace:
class org.hibernate.sql.results.graph.embeddable.internal.EmbeddableInitializerImpl cannot be cast to class org.hibernate.reactive.sql.results.graph.ReactiveInitializer (org.hibernate.sql.results.graph.embeddable.internal.EmbeddableInitializerImpl and org.hibernate.reactive.sql.results.graph.ReactiveInitializer are in unnamed module of loader io.quarkus.bootstrap.classloading.QuarkusClassLoader @2fc0cc3)

As far as I understand, this happens because Hibernate Reactive does not support JoinColumns, which then makes it fall back on the default Hibernate ORM implementation, which breaks because you can't run non-reactive code in a reactive context.

I think the problem is twofold. Ideally, this would be fixed such that it works, but also the exception in its current form is incredibly hard to debug. This took us a really long time to figure out, reproduce, and isolate from the rest of the entity code to figure out this was causing the issue.

I made a minimal reproduction of the issue, which you can pull from here: https://gitlab.com/l.s.andringa1/hibernate-reactive-reproducer. There is a unit test in that project that breaks with the explained issue.

Expected behavior

When running repository.find(), the entity should simply be retrieved from the database without throwing exceptions.

Actual behavior

Hibernate throws an exception around using non-reactive code in a reactive environment

How to Reproduce?

Reproducer: https://gitlab.com/l.s.andringa1/hibernate-reactive-reproducer

Steps:

  1. Clone repository
  2. Run EntityTest unit test
  3. Observe failure

Output of uname -a or ver

6.11.0-13-generic #14-Ubuntu SMP PREEMPT_DYNAMIC Sat Nov 30 23:51:51 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

Output of java -version

openjdk version "21.0.5" 2024-10-15

Quarkus version or git rev

3.17.4

Build tool (ie. output of mvnw --version or gradlew --version)

Gradle 8.9

Additional information

No response

Metadata

Metadata

Assignees

Labels

area/hibernate-reactiveHibernate Reactivearea/kotlinkind/bug-thirdpartyBugs that are caused by third-party components and not causing a major dysfunction of core Quarkus.

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions