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

Fix #13425 Hibernate ORM and Hibernate Reactive cannot be used in the same application #44473

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

lucamolteni
Copy link
Contributor

@lucamolteni lucamolteni commented Nov 13, 2024

Fixes #13425

I've added a test to verify the compatibility of both the extensions together.

This is not a big refactor as both extensions are still coupled together, but this lets users use both implementation in their Quarkus application.

The idea is to have a MultiplePersistenceProviderResolver https://github.com/quarkusio/quarkus/compare/main...lucamolteni:13425-ter?expand=1#diff-c1c6c402fc142de3b1c4d726cb080f2b856cf560b693a1686f52ad3a35a972f0R10

And filter the correct one at runtime

https://github.com/quarkusio/quarkus/compare/main...lucamolteni:13425-ter?expand=1#diff-db8c5c1b299098a43c5d8e4b3f3267e4bb72c6e7841536d9bbb487dcff8c54ffR88

There's also a new ReactivePersistenceUnit annotation https://github.com/quarkusio/quarkus/compare/main...lucamolteni:13425-ter?expand=1#diff-8c10ee8583155144d5c9f796e33b785471701a346c768b2f707fe3a036f0590dR24 in order to disambiguate the correct bean to be injected.

I've also changed the default name for the reactive persistence unit as there are effectively two together and they can't share the same name.

Connection strings are in two different fields so they don't collide
https://github.com/quarkusio/quarkus/compare/main...lucamolteni:13425-ter?expand=1#diff-6dd4fdea2c39574c084d9b03d106b6dd15b4877db728858cebf88641216bcd72R13

Feedbacks are welcome

Copy link

quarkus-bot bot commented Nov 13, 2024

Thanks for your pull request!

Your pull request does not follow our editorial rules. Could you have a look?

  • title should not contain an issue number (use Fix #1234 in the description instead)

This message is automatically generated by a bot.

@quarkus-bot quarkus-bot bot added area/hibernate-orm Hibernate ORM area/hibernate-reactive Hibernate Reactive labels Nov 13, 2024
Copy link

quarkus-bot bot commented Nov 13, 2024

/cc @gsmet (hibernate-orm), @yrodiere (hibernate-orm)

@lucamolteni lucamolteni changed the title Hibernate ORM and Hibernate Reactive cannot be used in the same application #13425 Fix #13425 iHibernate ORM and Hibernate Reactive cannot be used in the same application Nov 13, 2024
@lucamolteni lucamolteni changed the title Fix #13425 iHibernate ORM and Hibernate Reactive cannot be used in the same application Fix #13425 Hibernate ORM and Hibernate Reactive cannot be used in the same application Nov 13, 2024
@yrodiere
Copy link
Member

Thanks!

I'll have a closer look tomorrow, but a few early comments:

There's also a new ReactivePersistenceUnit annotation https://github.com/quarkusio/quarkus/compare/main...lucamolteni:13425-ter?expand=1#diff-8c10ee8583155144d5c9f796e33b785471701a346c768b2f707fe3a036f0590dR24 in order to disambiguate the correct bean to be injected.

Can this be more "hidden"? E.g. move the annotation to a clearly internal package, or even just don't make it a bean for Hibernate Reactive.

The reason I'm asking is that users really shouldn't be using the EntityManagerFactory for Hibernate Reactive, and thus @ReactivePersistenceUnit really has no use except internally, which could be confusing.

I've also changed the default name for the reactive persistence unit as there are effectively two together and they can't share the same name.

A few things:

  1. This is just for the EntityManagerFactory bean, right? So the problem would go away if the EntityManagerFactory for Hibernate Reactive was not a CDI bean?
  2. How will this work once we support named persistence units in the Hibernate Reactive extension?
  3. Wasn't that persistence unit already using a different name? I've seen <default-reactive> somewhere before...

@lucamolteni
Copy link
Contributor Author

I'll have a closer look tomorrow, but a few early comments:

There's also a new ReactivePersistenceUnit annotation https://github.com/quarkusio/quarkus/compare/main...lucamolteni:13425-ter?expand=1#diff-8c10ee8583155144d5c9f796e33b785471701a346c768b2f707fe3a036f0590dR24 in order to disambiguate the correct bean to be injected.

Can this be more "hidden"? E.g. move the annotation to a clearly internal package, or even just don't make it a bean for Hibernate Reactive.

The reason I'm asking is that users really shouldn't be using the EntityManagerFactory for Hibernate Reactive, and thus @ReactivePersistenceUnit really has no use except internally, which could be confusing.

I agree with your point, I'll work on it and see if I can hide it somehow. But yes it's just a matter of CDI injection (answering also 1 below)

I've also changed the default name for the reactive persistence unit as there are effectively two together and they can't share the same name.

A few things:

  1. This is just for the EntityManagerFactory bean, right? So the problem would go away if the EntityManagerFactory for Hibernate Reactive was not a CDI bean?
  2. How will this work once we support named persistence units in the Hibernate Reactive extension?

I don't see how this should prevent the multiple units to be implemented, it's something that has to be done from scratch anyway

  1. Wasn't that persistence unit already using a different name? I've seen <default-reactive> somewhere before...

I saw that as well, but I also saw the original persistence unit default string hardcoded and that was a problem, so I thought that keeping it separated would be better.

@FroMage
Copy link
Member

FroMage commented Nov 13, 2024

Impressive. I've no idea how to support this in Panache, though 😱

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/hibernate-orm Hibernate ORM area/hibernate-reactive Hibernate Reactive
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hibernate ORM and Hibernate Reactive cannot be used in the same application
3 participants