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

Use SelectionQuery/MutationQuery wherever possible in Panache + avoid warning HHH000104 #41547

Merged
merged 3 commits into from
Jul 1, 2024

Conversation

yrodiere
Copy link
Member

@yrodiere yrodiere commented Jun 28, 2024

  1. Moves to SelectionQuery/MutationQuery, which are the recommended way to create queries in Hibernate when using native APIs (Session).
  2. Fixes PanacheQuery: singleResultOptional() gives hibernate warning "HHH000104" #41459

Migration guide entry:

== Hibernate ORM with Panache

=== Move to `SelectionQuery`/`MutationQuery`

Panache now relies on different methods to run queries:
instead of calling `Session#createQuery`, which returns a `Query` object,
Panache now calls `Session#createSelectionQuery`/`Session#createMutationQuery`,
which returns a `SelectionQuery`/`MutationQuery`.

This may affect applications in the following way:

* _Some_ exceptions thrown in case of misuse won't get wrapped anymore.
For example an invalid query `String` may result in a `SemanticException`,
whereas it used to result in an `IllegalArgumentException` whose cause was a `SemanticException`.
Exceptions thrown in case of unexpected database content are unaffected.
For example `NoResultException` will still be thrown as it used to be.
* Application tests using Panache and relying on a mocked `Session` may not work anymore,
until they adjust their mocking to mock `Session#createSelectionQuery`/`Session#createMutationQuery`
instead of `Session#createQuery`.

@yrodiere yrodiere requested a review from FroMage June 28, 2024 10:23

This comment has been minimized.

This comment has been minimized.

yrodiere added 3 commits June 28, 2024 14:13
…simplify code

Don't use a limit to avoid warnings such as:

> HHH000104: firstResult/maxResults specified with collection fetch; applying in memory!

Simplify code because... we can.
@yrodiere yrodiere force-pushed the panache-selection-mutation branch from 777f10c to f6630d1 Compare June 28, 2024 12:57
Copy link

quarkus-bot bot commented Jun 28, 2024

Status for workflow Quarkus CI

This is the status report for running Quarkus CI on commit f6630d1.

✅ 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.

You can consult the Develocity build scans.

@yrodiere yrodiere added the triage/needs-review Issue that needs a review - remove label if all is clear label Jun 28, 2024
@@ -336,14 +335,9 @@ public <T extends Entity> T singleResult() {

@SuppressWarnings("unchecked")
public <T extends Entity> Optional<T> singleResultOptional() {
SelectionQuery hibernateQuery = createQuery(2);
Copy link
Member Author

Choose a reason for hiding this comment

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

Interestingly, we were using a limit for singleResultOptional, but not for singleResult :|

@gsmet gsmet merged commit 1df964d into quarkusio:main Jul 1, 2024
32 checks passed
Copy link

github-actions bot commented Jul 1, 2024

🙈 The PR is closed and the preview is expired.

gsmet added a commit to gsmet/quarkus that referenced this pull request Aug 8, 2024
gsmet added a commit to gsmet/quarkus that referenced this pull request Aug 8, 2024
danielsoro pushed a commit to danielsoro/quarkus that referenced this pull request Sep 20, 2024
@yrodiere yrodiere deleted the panache-selection-mutation branch October 3, 2024 07:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/documentation area/panache triage/needs-review Issue that needs a review - remove label if all is clear
Projects
Development

Successfully merging this pull request may close these issues.

PanacheQuery: singleResultOptional() gives hibernate warning "HHH000104"
2 participants