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
Document that DTOs don't work with native queries [DATAJPA-1714] #2009
Comments
Jens Schauder commented The referenced PR contains a reproducing test |
I'm having this issue even when not using a native query: Repository: @Query("SELECT cso.myField AS myField FROM MyEntity cso")
List<MyEntityDTO> testQuery(); DTO: @Value
public class MyEntityDTO {
private long myField;
} Error:
It, however, works just fine if I reference the constructor in the query: @Query("SELECT new com.company.package.MyEntityDTO(cso.myField) FROM MyEntity cso")
List<MyEntityDTO> testQuery(); |
@amhokies by the way - thank you for the workaround I searched for. But still waiting to be fixed! |
Any update on this? Thank you. |
For JPQL queries there is the constructor clause as described by @amhokies. The question is, should Spring Data JPA offer something beyond that?
|
The team decided that we will not implement this, since the drawbacks of both possible implementations are to big. You therefore have the following workarounds available:
I'll use this ticket to correct the documentation. |
Closes #2009 Related ticket: spring-projects/spring-data-commons#2382 Original pull request: #2237
Closes #2009 Related ticket: spring-projects/spring-data-commons#2382 Original pull request: #2237
Jens Schauder opened DATAJPA-1714 and commented
Trying to return a DTO from a native query results in an exception like the following:
Reference URL: https://stackoverflow.com/a/61255102/66686
Referenced from: pull request #419
1 votes, 2 watchers
The text was updated successfully, but these errors were encountered: