Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@JoinColumns breaks on Hibernate Reactive #45188

Closed
LarsSven opened this issue Dec 18, 2024 · 8 comments · Fixed by #45756
Closed

@JoinColumns breaks on Hibernate Reactive #45188

LarsSven opened this issue Dec 18, 2024 · 8 comments · Fixed by #45756
Assignees
Labels
area/hibernate-reactive Hibernate Reactive area/kotlin kind/bug-thirdparty Bugs that are caused by third-party components and not causing a major dysfunction of core Quarkus.
Milestone

Comments

@LarsSven
Copy link
Contributor

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

@LarsSven LarsSven added the kind/bug Something isn't working label Dec 18, 2024
Copy link

quarkus-bot bot commented Dec 18, 2024

/cc @DavideD (hibernate-reactive), @gavinking (hibernate-reactive), @geoand (kotlin)

@DavideD
Copy link
Contributor

DavideD commented Dec 18, 2024

THanks for the reproducer, I will have a look

@LarsSven
Copy link
Contributor Author

For reference, this is our production repository where we originally found the issue, https://gitlab.com/rug-digitallab/products/themis/themis-core/-/tree/ls/172-persistence?ref_type=heads

Here we get a slightly different error, as it tries to cast a different class:
class org.hibernate.sql.results.graph.entity.internal.EntityInitializerImpl cannot be cast to class org.hibernate.reactive.sql.results.graph.ReactiveInitializer (org.hibernate.sql.results.graph.entity.internal.EntityInitializerImpl and org.hibernate.reactive.sql.results.graph.ReactiveInitializer are in unnamed module of loader io.quarkus.bootstrap.classloading.QuarkusClassLoader @5b0dbfb)

But yeah this repository is of course a lot more cluttered, so best to refer to the minimised reporducer

@gsmet gsmet added kind/bug-thirdparty Bugs that are caused by third-party components and not causing a major dysfunction of core Quarkus. and removed kind/bug Something isn't working labels Dec 26, 2024
@LarsSven
Copy link
Contributor Author

@DavideD do you happen to know if this bug is resolvable in the near future? An important feature is currently blocked on this so we are thinking about whether it's reasonable to wait for this or move away from hibernate-reactive / redo our entity design to work around the bug.

@DavideD
Copy link
Contributor

DavideD commented Dec 26, 2024 via email

@LarsSven
Copy link
Contributor Author

@DavideD thanks a lot for taking your time for this. Have you had a chance to look at it?
Also is it sufficient to have an issue at the Quarkus project, or should an issue also be open at the hibernate-reactive repo?

@DavideD
Copy link
Contributor

DavideD commented Jan 15, 2025

I will have a look at this this week

@DavideD
Copy link
Contributor

DavideD commented Jan 20, 2025

Hi, we figured out the problem. It's the same as this one: hibernate/hibernate-reactive#2060

It will be fixed in the next release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/hibernate-reactive Hibernate Reactive area/kotlin kind/bug-thirdparty Bugs that are caused by third-party components and not causing a major dysfunction of core Quarkus.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants