Closed vitos23 closed 4 months ago
Projection interfaces must not be implemented by the aggregate which the repository manages. If it implements the interface we cannot distinguish between a lookup for the full entity behind the interface or just the reduced set of properties. A simple workaround would be to create an additional, empty projection interface that extends UserInfo
to make clear what you're tying to do.
Thanks for the workaround. It would be nice to see such limitations covered in the documentation.
Interface-based projection does not work properly when querying for not the whole entity but specified fields and returned interface is implemented by the entity.
Suppose we have:
Let's put some data in the
users
table:userRepository.save(User("user", 123))
. And if we executefindAllInfos
we will get the following error:The full example is here.
The root of the problem is on the 139th line of the
ResultProcessor
class (spring-data-commons), in the methodprocessResult
:type.isProjecting()
returnsfalse
butsource
is justObject
with queried fields, not the entity. Therefore, projection is not created.