Panache Query projection doesn't work as expected when entity has an optional one-to-one field #36497
Description
Describe the bug
If the entity has an optional one-to-one field, and use project
, the find
query will only return rows where the referenced column exist. My current work around is to skip the project
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 -
class Person: PanacheEntity() {
@OneToOne(mappedBy = "job", fetch = FetchType.EAGER, optional = true)
open var job: Job? = null
}
class Job: PanacheEntity() {
@OnetoOne(fetch = FetchType.EAGER)
@JoinColumn(name = "person_id")
open lateinit var person: Person
}
And you have a DTO like this to project
Person
entity -
class PersonDto(val job: Job?)
And you use the query like this
repository.find("id = ?1", id).project(PersonDto::class.java)
In the result, you will only see Person
object who has a corresponding Job
even though Person
rows without a job should also be included in the result.
Output of uname -a
or ver
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
or gradlew --version
)
Gradle 8.1.
Additional information
No response
Activity