Closed
Description
Hello,
Unfortunately any kind of projections doesn't work with data-repositories. It's probably caused by
return returnedType.isProjecting() ? returnedType.getReturnedType() : returnedType.getDomainType();
The above was tested locally and it worked, please kindly check.
Metadata
Metadata
Assignees
Labels
Type
Projects
Relationships
Development
No branches or pull requests
Activity
mp911de commentedon Oct 6, 2020
Can you provide a test case that shows that projections are broken? Our integration tests for projections pass so it would be good to know in which case projections don't work.
alesikov commentedon Oct 6, 2020
My bad, forgot to mention that the issue is related to
@Query
-annotated methods which produce class-based projections.Apparently the tests don't cover the scenario when projection has different field names than the entity
Managed to reproduce the same using integration tests you mentioned previously, the proposed fix still works. Please try testing against the following:
mp911de commentedon Oct 7, 2020
DTO projections work actually on top of the repository entity type in the sense that DTO's are a subset of entity properties. Additional properties aren't really expected here.
The following code should explain the underlying assumptions:
Assuming the
firstName
property maps onto thefn
column in your database, then a derived query would apply proper fieldname mapping:resulting in the SQL:
If we now translate that behavior to String-based queries, what would the select look like for:
Is it
SELECT fn FROM person
or would it rather beSELECT fn AS firstName FROM person
?mp911de commentedon Oct 7, 2020
Likely, using the domaintype -> DTO for derived query processing and reading directly into the DTO for string-based queries is a good middleground as for string queries the type declaration and
@Query
are pretty close. For derived queries, you typically don't have much control over the projected queries.#475 - Refine projection result mapping.
#475 - Polishing.
mp911de commentedon Oct 8, 2020
That change is in place now.
alesikov commentedon Oct 11, 2020
Thank you for the amazing project