quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.56k stars 2.62k forks source link

Support multiple persistence units for Hibernate Reactive #21110

Open kazik666 opened 2 years ago

kazik666 commented 2 years ago

Describe the bug

In my test application.yaml I have configuration like below:

datasource:
  first:
    devservices:
      enabled: true
      image-name: mysql/mysql-server:8.0.21
    db-kind: mysql
  second:
    devservices:
      enabled: true
      image-name: mysql/mysql-server:8.0.21
    db-kind: mysql
hibernate-orm:
  first:
    datasource: first
    packages: com.db.model.first
    sql-load-script: import-first.sql
    database:
      generation: drop-and-create
  second:
    datasource: second
    packages: com.db.model.second
    sql-load-script: import-second.sql
    database:
      generation: drop-and-create

When I'am running tests I see warning message in console: WARN: Skipping registration of ReactiveSessionFactoryProducer and ReactiveSessionProducer because exactly one persistence unit is required for their registration

And after that test failed with: java.lang.NullPointerException: Cannot invoke "org.hibernate.reactive.mutiny.Mutiny$Session.createQuery(String)" because "em" is null

Expected behavior

Two persistent reactive units should be initialized properly.

Actual behavior

Non of reactive persistent units was initialized.

How to Reproduce?

No response

Output of uname -a or ver

Linux 5.13.0-20-generic #20-Ubuntu SMP Fri Oct 15 14:21:35 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Output of java -version

16.0.2

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.4.0.Final

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

Apache Maven 3.6.2

Additional information

No response

quarkus-bot[bot] commented 2 years ago

/cc @DavideD, @Sanne, @gavinking

kazik666 commented 2 years ago

Any news?

geoand commented 2 years ago

cc @gsmet

SetoKaiba commented 2 years ago

Hi. Why isn't multiple persistence units supported for Hibernate Reactive? The original hibernate reactive seems to support multiple persistence unit. What's the concern about this? I think add an annotation with persistence unit name and use producer method with InjectionPoint will be able to produce the Mutiny.SessionFactory for the specific persistence unit. Why not? And I'd like to know the reason why persistence.xml is not supported for Hibernate Reactive.

I see that resteasy-reactive has become the default rest layer. So I'd like to write whole app in reactive style. But the Hibernate Reactive is not with all the features I need.

Sanne commented 2 years ago

Hi. Why isn't multiple persistence units supported for Hibernate Reactive? The original hibernate reactive seems to support multiple persistence unit. What's the concern about this?

There's no instrinsic limitation, as you noticed Hibernate Reactive upstream can deal with multiple persistence units and we do plan to eventually support this in Quarkus as well.

But currently the Hibernate Reactive extension for Quarkus is in a problematic shape: it's highly coupled to the core of the Hibernate ORM blocking extension, and the presence of it actually taints the state of the blocking ORM instances. It needs to be rewritten with a more flexible design.

But we're aiming to support Hibernate ORM 6 first, and in terms of project steering it's not a good idea to have these big initiatives working in parallel; since we know Hibernate Reactive also needs substantial changes to make itself ready for ORM6, I feel that re-implementing the Hibernate Reactive extension for Quarkus is better deferred to when such other tasks have been done.

This is the order in which I expect us to make progress:

  1. Quarkus moves to Jakarta API (this is being worked on)
  2. Hibernate Reactive moves to Hibernate ORM 6 (this is being worked on)
  3. both the Hibernate ORM and Hibernate Reactive extensions need to be rewritten to support ORM6 - and that's a good time to better model the proper coupling

Since there's already big changes being made in parallel across all projects, it would be problematic to start the refactoring of the Hibernate Reactive extension in parallel as well. Not least because it's the same people working on these points, so it's not like we'd finish faster :)

And I'd like to know the reason why persistence.xml is not supported for Hibernate Reactive.

The persistence.xml support for Hibernate ORM blocking is meant as a facilittion for people who are migrating from JPA. I don't think people who are creating a brand new application in Quarkus should use a persistence.xml, and since clearly Hibernate Reactive users aren't - at least eaily - going to expect "copying over" an existing persistence layer, this facility isn't very useful for an Hibernate Reactive user.

I might be wrong, I'm actually interested why you're asking for it? How important is that for you?

debu999 commented 1 year ago

Hi @Sanne seems there has been somework on this. Is this now being planned for being supported in Quarkus. We now do Reactive APP + Jdbc Database conneciton via agroal.

csotiriou commented 1 year ago

Actually, since we hit this limitation in our case as well, we need to take an architectural decision on our side and use the plain hibernate ORM, but the rest of our service is written in RESTEasy Reactive.

Question: does Resteasy Reactive play nicely with the plain Hibernate (non-reactive) client without having any issues later down the road for the microservices that mix those two?

geoand commented 1 year ago

Yes, RESTEasy Reactive works perfectly with both flavors of Hibernate

mmasliukov commented 10 months ago

Hey @Sanne, could you please update if multiple persistence units supported by latest quarkus version?

michalvavrik commented 10 months ago

Hey @Sanne, could you please update if multiple persistence units supported by latest quarkus version?

Main branch docs says it is not https://quarkus.io/version/main/guides/hibernate-reactive#hr-limitations.

alexgelb1 commented 4 months ago

Is there any update on this ticket or any ideas when this will be fixed?