Entity return type marked as projection #3308
Labels
status: waiting-for-feedback
We need additional information before we can continue
status: waiting-for-triage
An issue we've not yet triaged
Due to spring-projects/spring-data-jpa#3076 we've noticed a bug occurring in an old repository class of ours.
The setup is as follows:
This is the result of some legacy code, and likely someone being too lazy to create a separate repository class for just one method.
The QueryMethod object for this repository method now returns the class EntityA instead of EntityB when calling its
getDomainClass
method. The logic used to determine the correct domain class seems to always prioritize the repository type over the method domain type.spring-data-commons/src/main/java/org/springframework/data/repository/query/QueryMethod.java
Line 115 in f28a2c2
This then causes the ReturnedType object for the method to mark the return type as a projection since the return type doesn't match the domain type, which then triggers the query rewrite from the issue above.
All that then results in a runtime exception since the generated constructor query is incorrect as our EntityB class doesn't have a constructor and the query validation fails with an obscure syntax error.
For now I'll fix this by just moving the method in question to a new repository, but it still feels like this should work, and it has worked for a long time without any issues.
The text was updated successfully, but these errors were encountered: