-
Notifications
You must be signed in to change notification settings - Fork 346
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Dynamic projections for interfaces does not work #1813
Comments
This is a feature that will support interface based projection like below code? interface MyEntityInterfaceProjection {
String status();
Long id();
} |
Not, exactly @ngocnhan-tran1996. This issue target the dynamic projects more specifically, which can use interface of course as the target type. The interface based projections should work, though, as they are documented. You have any issues? |
correct me if I miss something. I take a look your testcase and it doesn't work, but if I add From document
@Test
@Disabled // Enable to see what happens
void whenDynamicProjectsAreInUseViaInterfaces_thenBlast() {
saveInitialEntity();
Optional<MyEntityInterfaceProjection> active = myEntityRepository.findProjectionByStatus("active", MyEntityInterfaceProjection.class);
Assertions.assertThat(active)
.isPresent()
.hasValueSatisfying(myEntityProjection -> {
Assertions.assertThat(myEntityProjection.id() != null && myEntityProjection.status().equalsIgnoreCase("active")).isTrue();
});
}
// more code
interface MyEntityInterfaceProjection {
String status(); // add get prefix
Long id(); // add get prefix
} |
Yeah, it does indeed. |
As @ngocnhan-tran1996 correctly pointed out, the exception happens, because the interface doesn't have any getters. But I took up your suggestion of a more explicit exception with the referenced PR. |
I don't think catching an exception is the right approach. Instead, if the list of input properties is empty, then we should select everything. We had similar cases with projections that use In such a case, we expect that the underlying object is fully materialized so that projections can compute their own values. |
FWIW, the same issue exists in JPA. With spring-projects/spring-data-commons#3164, I fixed the |
When I upgrade the provided example to use The test fails later when the interface methods are used, because nothing is backing them. But that is to be expected. I therefore close this ticket. |
I've created test in the playground repo to demonstrate the issue.
The fact is - currently, the
JdbcQueryCreator.complete()
fails to build aSELECT
clause in case of interfaces to be used in dynamic projections. The stack trace is:That seems to happen only for dynamic projections, interface based projection on their own should be fine.
I think it's going to be great to add a support for this.
The text was updated successfully, but these errors were encountered: