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

Hibernate reactive panache refactoring #29761

Merged
merged 2 commits into from
Feb 6, 2023

Conversation

mkouba
Copy link
Contributor

@mkouba mkouba commented Dec 8, 2022

  • do not store the current reactive session in the CDI request context but instead in the vertx duplicated context
  • do not offload execution of a panache entity method on the current vertx context but instead validate that the method is executed on the vetx duplicated context
  • introduce @WithSession, @WithSessionOnDemand and @WithTransaction bindings and interceptors
  • deprecate ReactiveTransactional (WithTransaction should be used instead)
  • ReactiveTransactionalInterceptor can only be used for methods that return Uni; this is validated at build time
  • if resteasy-reactive is present then automatically add the @WithSessionOnDemand binding to all resource methods on classes that use a panache entity
  • remove the quarkus-integration-test-hibernate-reactive-panache-blocking module
  • quarkus-test-vertx - run the test method on a duplicated vertx context even if the @RunOnVertxContext is not present but the @TestReactiveTransaction is
  • update integration-tests/hibernate-reactive-panache-kotlin
  • update documentation

@quarkus-bot quarkus-bot bot added area/arc Issue related to ARC (dependency injection) area/hibernate-reactive Hibernate Reactive area/panache area/persistence OBSOLETE, DO NOT USE labels Dec 8, 2022
@geoand geoand requested review from FroMage and Sanne December 9, 2022 08:47
@mkouba mkouba force-pushed the hibernate-reactive-panache-next branch from edc1749 to 4b401be Compare December 15, 2022 11:19
@mkouba mkouba requested a review from DavideD December 15, 2022 12:15
@mkouba mkouba force-pushed the hibernate-reactive-panache-next branch 3 times, most recently from e8b9bbe to 50a181f Compare December 19, 2022 08:22
@FroMage
Copy link
Member

FroMage commented Dec 19, 2022

Sorry for the late review :(

@mkouba mkouba force-pushed the hibernate-reactive-panache-next branch from 50a181f to db9a4ec Compare December 21, 2022 08:27
@mkouba
Copy link
Contributor Author

mkouba commented Dec 21, 2022

Sorry for the late review :(

No problem, better late than never! ;-)

@mkouba mkouba force-pushed the hibernate-reactive-panache-next branch from db9a4ec to 0b56ce8 Compare December 21, 2022 09:20
Copy link
Member

@FroMage FroMage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.
Do you think there's any need for a @WithoutSession to disable the automatic @WithSessionIfNeeded? I don't think so.
In Renarde, I automatically add the @Transactional annotation to POST/PUT/DELETE methods, but I've often wondered if I should add a @NoTransaction annotation to disable this. Perhaps we need a @WithoutTransaction in HR/Panache, so that I can avoid auto-adding @WithTransaction when I integrate HR in Renarde?

@mkouba
Copy link
Contributor Author

mkouba commented Dec 21, 2022

Do you think there's any need for a @WithoutSession to disable the automatic @WithSessionIfNeeded? I don't think so.

I agree.

In Renarde, I automatically add the @Transactional annotation to POST/PUT/DELETE methods, but I've often wondered if I should add a @NoTransaction annotation to disable this. Perhaps we need a @WithoutTransaction in HR/Panache, so that I can avoid auto-adding @WithTransaction when I integrate HR in Renarde?

What would be the point of @WithoutTransaction in the context of HR/Panache? I mean this is the default, unless you specify @WithTransaction so I don't really understand...

@FroMage
Copy link
Member

FroMage commented Dec 21, 2022

Because I automatically add the @Transactional on every method :) So this would be a way to turn it off. It's not needed for lazy sessions because they're inexpensive and you only pay when used. But for transactions, that's probably expensive if not used, because HR transactions are not lazy like ORM transactions.

@mkouba
Copy link
Contributor Author

mkouba commented Dec 21, 2022

Well, I think that such an annotation should go into Renarde then...

@FroMage
Copy link
Member

FroMage commented Dec 22, 2022

Yes, that's very possible.

@sberyozkin
Copy link
Member

Hi @mkouba, not sure it is relevant, I was trying https://github.com/quarkusio/quarkus-quickstarts/tree/main/kafka-panache-reactive-quickstart (I composing a security demo from various quickstarts), and I've noticed, I believe, that if quarkus-reactive-pg-client is not included here, https://github.com/quarkusio/quarkus-quickstarts/blob/main/kafka-panache-reactive-quickstart/pom.xml#L41, then this code, https://github.com/quarkusio/quarkus-quickstarts/blob/main/kafka-panache-reactive-quickstart/src/main/java/org/acme/panache/PriceStorage.java#L18, returns NPE.

If it is indeed the case (confirmed) then may be it can make sense to have quarkus-hibernate-panache-reactive directly depending on quarkus-reactive-pg-client ? In devmode, it would be nice to be able to only add quarkus-hibernate-panache-reactive to the pom, without having to add quarkus-reactive-pg-client, if it is required anyway...

Sorry if it is off-topic

@mkouba
Copy link
Contributor Author

mkouba commented Jan 4, 2023

If it is indeed the case (confirmed) then may be it can make sense to have quarkus-hibernate-panache-reactive directly depending on quarkus-reactive-pg-client ? In devmode, it would be nice to be able to only add quarkus-hibernate-panache-reactive to the pom, without having to add quarkus-reactive-pg-client, if it is required anyway...

I don't think it's required. I mean you just need to add an reactive SQL client extension like for any Hibernate Reactive application.

@sberyozkin
Copy link
Member

But if without it NPE is returned then may be it is required ?

@sberyozkin
Copy link
Member

Sorry, see what you mean, there are a few client types, may be a better error message can be returned like please add a client, etc

@mkouba
Copy link
Contributor Author

mkouba commented Jan 4, 2023

Sorry, see what you mean, there are a few client types, may be a better error message can be returned like please add a client, etc

I wonder if the NPE is thrown for vanilla Hibernate Reactive as well?

@sberyozkin
Copy link
Member

sberyozkin commented Jan 4, 2023

I wonder if the NPE is thrown for vanilla Hibernate Reactive as well?

I haven't tried, sorry, I just looked at Hibernate Panache Reactive as the code looks simpler which is what I'll need to for the introduction demo

@mkouba mkouba force-pushed the hibernate-reactive-panache-next branch from d804b2a to f7f931e Compare February 3, 2023 13:26
@mkouba mkouba marked this pull request as ready for review February 3, 2023 13:26
@quarkus-bot

This comment has been minimized.

@gsmet gsmet added the triage/needs-rebase This PR needs to be rebased first because it has merge conflicts label Feb 4, 2023
- do not store the current reactive session in the CDI request context
but instead in the vertx duplicated context
- do not offload execution of a panache entity method on the current
vertx context but instead validate that the method is executed on the
vetx duplicated context
- introduce WithSession, WithSessionOnDemand and WithTransaction
bindings and interceptors
- deprecate ReactiveTransactional
- ReactiveTransactionalInterceptor can only be used for methods that
return Uni/Multi; this is validated at build time
- if resteasy-reactive is present then automatically add WithSessionOnDemand binding to all resource methods on classes that use a panache entity
- also remove the quarkus-integration-test-hibernate-reactive-panache-blocking module
- quarkus-test-vertx - run the test method on a duplicated vertx context even if the RunOnVertxContext is not present but the TestReactiveTransaction is
- neither Hibernate Reactive nor reactive clients support streaming
- furthermore, we're not able to provide a Panache#withTransaction()
alternative for Multi without bypassing Hibernate Reactive API
@mkouba mkouba force-pushed the hibernate-reactive-panache-next branch from f7f931e to 99c4b70 Compare February 6, 2023 10:18
@mkouba mkouba removed the triage/needs-rebase This PR needs to be rebased first because it has merge conflicts label Feb 6, 2023
@quarkus-bot
Copy link

quarkus-bot bot commented Feb 6, 2023

✔️ The latest workflow run for the pull request has completed successfully.

It should be safe to merge provided you have a look at the other checks in the summary.

@mkouba
Copy link
Contributor Author

mkouba commented Feb 6, 2023

The CI is green now!

FTR all Multi<T> stream() methods were removed.

@FroMage @DavideD @Sanne I'm going to merge this pull reuqest but I do expect some follow-ups based on potential feedback.

@mkouba mkouba merged commit bad55f4 into quarkusio:main Feb 6, 2023
@quarkus-bot quarkus-bot bot added this to the 3.0 - main milestone Feb 6, 2023
@DavideD
Copy link
Contributor

DavideD commented Feb 7, 2023

Thanks @mkouba

@FroMage
Copy link
Member

FroMage commented Feb 7, 2023

+1

michalvavrik added a commit to michalvavrik/quarkus-test-suite that referenced this pull request Feb 9, 2023
Disables messaging/qpid till quarkus-qpid-jms  that uses Jakarta is released. Also disables external application tests till external projects (QS, Workshops, Todo app) migrates to Jakarta (that's till they use Quarkus 3+). Javax stuff is migrated to Jakarta and FW bumped to 1.3.0.Beta4 that also sports jakarta. Changes in Panache Hibernate Reactive module are forced by quarkusio/quarkus#29761
michalvavrik added a commit to michalvavrik/quarkus-test-suite that referenced this pull request Feb 9, 2023
Disables messaging/qpid till quarkus-qpid-jms  that uses Jakarta is released. Also disables external application tests till external projects (QS, Workshops, Todo app) migrates to Jakarta (that's till they use Quarkus 3+). Javax stuff is migrated to Jakarta and FW bumped to 1.3.0.Beta4 that also sports jakarta. Changes in Panache Hibernate Reactive module are forced by quarkusio/quarkus#29761
michalvavrik added a commit to michalvavrik/quarkus-test-suite that referenced this pull request Feb 10, 2023
Disables messaging/qpid till quarkus-qpid-jms  that uses Jakarta is released. Also disables external application tests till external projects (QS, Workshops, Todo app) migrates to Jakarta (that's till they use Quarkus 3+). Javax stuff is migrated to Jakarta and FW bumped to 1.3.0.Beta4 that also sports jakarta. Changes in Panache Hibernate Reactive module are forced by quarkusio/quarkus#29761
michalvavrik added a commit to michalvavrik/quarkus-test-suite that referenced this pull request Feb 11, 2023
Disables messaging/qpid till quarkus-qpid-jms  that uses Jakarta is released. Also disables external application tests till external projects (QS, Workshops, Todo app) migrates to Jakarta (that's till they use Quarkus 3+). Javax stuff is migrated to Jakarta and FW bumped to 1.3.0.Beta4 that also sports jakarta. Changes in Panache Hibernate Reactive module are forced by quarkusio/quarkus#29761
michalvavrik added a commit to michalvavrik/quarkus-test-suite that referenced this pull request Feb 12, 2023
Disables messaging/qpid till quarkus-qpid-jms  that uses Jakarta is released. Also disables external application tests till external projects (QS, Workshops, Todo app) migrates to Jakarta (that's till they use Quarkus 3+). Javax stuff is migrated to Jakarta and FW bumped to 1.3.0.Beta4 that also sports jakarta. Changes in Panache Hibernate Reactive module are forced by quarkusio/quarkus#29761
michalvavrik added a commit to michalvavrik/quarkus-test-suite that referenced this pull request Feb 12, 2023
Disables messaging/qpid till quarkus-qpid-jms  that uses Jakarta is released. Also disables external application tests till external projects (QS, Workshops, Todo app) migrates to Jakarta (that's till they use Quarkus 3+). Javax stuff is migrated to Jakarta and FW bumped to 1.3.0.Beta4 that also sports jakarta. Changes in Panache Hibernate Reactive module are forced by quarkusio/quarkus#29761
michalvavrik added a commit to michalvavrik/quarkus-test-suite that referenced this pull request Feb 12, 2023
Disables messaging/qpid till quarkus-qpid-jms  that uses Jakarta is released. Also disables external application tests till external projects (QS, Workshops, Todo app) migrates to Jakarta (that's till they use Quarkus 3+). Javax stuff is migrated to Jakarta and FW bumped to 1.3.0.Beta4 that also sports jakarta. Changes in Panache Hibernate Reactive module are forced by quarkusio/quarkus#29761
michalvavrik added a commit to michalvavrik/quarkus-test-suite that referenced this pull request Feb 12, 2023
Disables messaging/qpid till quarkus-qpid-jms  that uses Jakarta is released. Also disables external application tests till external projects (QS, Workshops, Todo app) migrates to Jakarta (that's till they use Quarkus 3+). Javax stuff is migrated to Jakarta and FW bumped to 1.3.0.Beta4 that also sports jakarta. Changes in Panache Hibernate Reactive module are forced by quarkusio/quarkus#29761
michalvavrik added a commit to michalvavrik/quarkus-test-suite that referenced this pull request Feb 13, 2023
Disables messaging/qpid till quarkus-qpid-jms  that uses Jakarta is released. Also disables external application tests till external projects (QS, Workshops, Todo app) migrates to Jakarta (that's till they use Quarkus 3+). Javax stuff is migrated to Jakarta and FW bumped to 1.3.0.Beta4 that also sports jakarta. Changes in Panache Hibernate Reactive module are forced by quarkusio/quarkus#29761
michalvavrik added a commit to michalvavrik/quarkus-test-suite that referenced this pull request Feb 13, 2023
Disables messaging/qpid till quarkus-qpid-jms  that uses Jakarta is released. Also disables external application tests till external projects (QS, Workshops, Todo app) migrates to Jakarta (that's till they use Quarkus 3+). Javax stuff is migrated to Jakarta and FW bumped to 1.3.0.Beta4 that also sports jakarta. Changes in Panache Hibernate Reactive module are forced by quarkusio/quarkus#29761
michalvavrik added a commit to michalvavrik/quarkus-test-suite that referenced this pull request Feb 13, 2023
Disables messaging/qpid till quarkus-qpid-jms  that uses Jakarta is released. Also disables external application tests till external projects (QS, Workshops, Todo app) migrates to Jakarta (that's till they use Quarkus 3+). Javax stuff is migrated to Jakarta and FW bumped to 1.3.0.Beta4 that also sports jakarta. Changes in Panache Hibernate Reactive module are forced by quarkusio/quarkus#29761
michalvavrik added a commit to michalvavrik/quarkus-test-suite that referenced this pull request Feb 14, 2023
Disables messaging/qpid till quarkus-qpid-jms  that uses Jakarta is released. Also disables external application tests till external projects (QS, Workshops, Todo app) migrates to Jakarta (that's till they use Quarkus 3+). Javax stuff is migrated to Jakarta and FW bumped to 1.3.0.Beta4 that also sports jakarta. Changes in Panache Hibernate Reactive module are forced by quarkusio/quarkus#29761
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants