-
Notifications
You must be signed in to change notification settings - Fork 682
Add support for class based projections [DATACMNS-1013] #1463
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
Comments
Oliver Drotbohm commented That's actually already supported as shown in the example here. I guess the point you missed is that classes don't actually use the projection factory code path but are translated into e.g. constructor expressions in JPA or just handed to the converter in MongoDB. Anything I miss? |
Thomas Darimont commented Ah thanks, I missed that it works if there is a constructor. However sometimes you don't have a constructor on the projection type and you cannot simply add one. Btw. would be nice if the error message would state the fact that a constructor was missing instead of just saying: |
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed. |
Our DTO-based projections in MongoDB, Neo4j, and Cassandra support property-population already. JPA remains as a module where we should provide a similar level of convenience via spring-projects/spring-data-jpa#2327. |
Thomas Darimont opened DATACMNS-1013 and commented
Currently Spring Data Repositories support dynamic proxy based entity projections that expose persistent properties based on property declarations on an interface.
In some occasions it would be handy to work with class based projections directly, e.g. to avoid overhead (memory, reflective method invocations),
less garbage creation etc.
It seems to be enough to add an additional converter to the
ConversionService
instance in:org.springframework.data.repository.query.ResultProcessor.ProjectingConverter
which dynamically checks for compatible projection type and creates the projection instance and copies the mapped properties over to the new instance.I created a small PoC as a gist: https://gist.github.com/thomasdarimont/c59ac8679aae04be8ce0cd73af10b59e
It effectively allows to map the following entity
Via this repository:
onto this "projection type"
No further details from DATACMNS-1013
The text was updated successfully, but these errors were encountered: