Skip to content

Rewrite string-queries to use constructor expressions when return type is DTO #3076

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
gregturn opened this issue Jul 19, 2023 · 0 comments
Closed
Assignees
Labels
in: query-parser Everything related to parsing JPQL or SQL theme: projections Refinements around DTO and interface projections type: enhancement A general enhancement

Comments

@gregturn
Copy link
Contributor

gregturn commented Jul 19, 2023

Consider the following query:

@Entity
class Person { … }

class PersonProjection { … }


@Query("SELECT p FROM Person p")
PersonProjection findBy(…)

The query selects items from the Person entity while its return type is a DTO projection.

It would be good to rewrite such queries to use DTO projections for matching properties along the lines of:

@Query("SELECT new com.acme.PersonProjection(p.firstName, p.lastName) FROM Person p")
PersonProjection findBy(…)
@gregturn gregturn self-assigned this Jul 19, 2023
@gregturn gregturn added type: enhancement A general enhancement in: query-parser Everything related to parsing JPQL or SQL labels Jul 19, 2023
@mp911de mp911de added the theme: projections Refinements around DTO and interface projections label Aug 13, 2024
@mp911de mp911de assigned mp911de and unassigned gregturn Aug 20, 2024
@mp911de mp911de changed the title Add ability to rewrite queries when return type is DTO to leverage "new com.EntityDto" notation. Rewrite string-queries to use constructor expressions when return type is DTO Sep 23, 2024
@mp911de mp911de added this to the 3.5 M1 (2025.0.0) milestone Dec 3, 2024
mp911de added a commit that referenced this issue Dec 3, 2024
…e is DTO.

We now rewrite String-based JPA queries to use constructor expressions when either selecting the entity or selecting individual properties.

We do not rewrite queries that already use constructor expressions.

Closes #3076
mp911de added a commit that referenced this issue Dec 3, 2024
christophstrobl pushed a commit that referenced this issue Dec 5, 2024
…e is DTO.

We now rewrite String-based JPA queries to use constructor expressions when either selecting the entity or selecting individual properties.

We do not rewrite queries that already use constructor expressions.

Closes #3076
christophstrobl pushed a commit that referenced this issue Dec 5, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
in: query-parser Everything related to parsing JPQL or SQL theme: projections Refinements around DTO and interface projections type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants