-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Panache Query projection doesn't work as expected when entity has an optional one-to-one field #36497
Comments
/cc @FroMage (panache), @evanchooly (kotlin), @geoand (kotlin), @loicmathieu (panache) |
I have the same problem. Result sql is using JOIN, so, when missing releation in database, whole result is empty. There is no way, how to change join to 'left/right join'. |
facing the same issue even on @manytoone relationships where the field (foreign key) may be null. Seems like Panache ignores optional=true, nullable=true and even jakarta @nullable |
Any update on this? I don't understand why LEFT JOIN isn't the default option instead of INNER JOIN in this case. |
Small update, manual joining may do the trick. Interestingly, relation MUST be named same as This would work. Notice repository.find("FROM MyEntity me LEFT JOIN me.relation relation").project(EntityDTO.class).list() Changing P.S. Using |
Another small update, this has nothing to do with projections, but with way how hibernate handles implicit joins. So won't get fixed. |
@yrodiere it looks more like an Hibernate ORM behavior than a Quarkus issue? |
Hey,
It does. Though since it was marked as Panache only, I didn't get notified about it :) @ha-shine @darmanovic there's been fixes for similar bugs in recent versions of Hibernate ORM; is this still a problem with Quarkus 3.17.5? |
update: tested again with v 3.17.6, problem remains the same. |
Thanks for checking! Can you please provide a reproducer? |
Thanks @darmanovic for the reproducer. First, I agree this has nothing to do with projections, and nothing to do with Quarkus: it's purely related to Hibernate ORM, as you mentioned. I created a reproducer with vanilla Hibernate ORM: https://github.com/yrodiere/hibernate-test-case-templates/tree/quarkus-36497 The crux of the issue is that in this query:
... The left join is actually pointless. Indeed, we're writing On the other hand, the following query would work exactly as you expect, because there is a
There is a second issue in the behavior of @gavinking Do you think there's something we could improve in Hibernate? For the first issue I think the behavior is correct, but dodgy. Maybe pointless joins could be reported with warnings/errors? Or we could just forbid left joins that don't specify a "root name". In either case we'd have to disable these behavior in JPA compliance mode, though... For the second issue I'd lean towards considering it's a bug, considering the javadoc of
|
I created https://hibernate.atlassian.net/browse/HHH-19065 upstream, feel free to chime in there. |
I think you're right, and we might be able to treat a (non-
Nope, JPA requires the identification variable, so the spec is not a constraint here.
It's definitely a bug. |
Thanks @yrodiere and @gavinking for your responses. As a developer who's been using Panache, I find it unfortunate that Panache doesn’t generate LEFT JOIN with identification variable, but I can understand why that’s the case at the moment. If it did, working with projections would be so much easier! |
FWIW after some discussion I submitted a suggestion to the JPA spec, which may make your use case more straightfoward to address: jakartaee/persistence#697 To anyone getting here by accident (I know @darmanovic understands that, but want to be clear), note this is an improvement aiming at making the syntax less verbose. It does not add any feature, you can do the same currently by specifying left joins in your query explicitly (and naming the result of these joins, see #36497 (comment)) |
Describe the bug
If the entity has an optional one-to-one field, and use
project
, thefind
query will only return rows where the referenced column exist. My current work around is to skip theproject
and just do manual mapping in Kotlin.Expected behavior
It should return every rows including those with optional field empty.
Actual behavior
No response
How to Reproduce?
Say you have these entities -
And you have a DTO like this to
project
Person
entity -And you use the query like this
In the result, you will only see
Person
object who has a correspondingJob
even thoughPerson
rows without a job should also be included in the result.Output of
uname -a
orver
Darwin Htets-Mac-Studio.local 23.0.0 Darwin Kernel Version 23.0.0: Fri Sep 15 14:41:43 PDT 2023; root:xnu-10002.1.13~1/RELEASE_ARM64_T6000 arm64
Output of
java -version
17.0.8
GraalVM version (if different from Java)
No response
Quarkus version or git rev
3.4.3
Build tool (ie. output of
mvnw --version
orgradlew --version
)Gradle 8.1.
Additional information
No response
The text was updated successfully, but these errors were encountered: