Skip to content
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

R2dbcEntityTemplate fails to instantiate interface using fluent as(…) projection #1690

Closed
shuaqiu opened this issue Dec 6, 2023 · 4 comments
Labels
type: regression A regression from a previous release

Comments

@shuaqiu
Copy link

shuaqiu commented Dec 6, 2023

I have define a query as

    public Mono<IMember> findById(final String id) {
        final Query query = Query
            .query(CriteriaBuilder.buildIdQuery(id));
        return entityTemplate.select(MemberBo.class)
            .from(TABLE__MEMBER)
            .as(IMember.class)
            .matching(query)
            .first();
    }

while IMember is the super interface of MemberBo.

The query can correctly run at version 3.1.5 of spring-data-r2dbc, but throws exception after upgrade to version 3.2.0

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.member.api.bean.IMember]: Specified class is an interface
	at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:137) ~[spring-beans-6.1.1.jar:6.1.1]
	at org.springframework.data.mapping.model.ReflectionEntityInstantiator.instantiateClass(ReflectionEntityInstantiator.java:139) ~[spring-data-commons-3.2.0.jar:3.2.0]
	at org.springframework.data.mapping.model.ReflectionEntityInstantiator.createInstance(ReflectionEntityInstantiator.java:57) ~[spring-data-commons-3.2.0.jar:3.2.0]
	at org.springframework.data.mapping.model.ClassGeneratingEntityInstantiator.createInstance(ClassGeneratingEntityInstantiator.java:98) ~[spring-data-commons-3.2.0.jar:3.2.0]
	at org.springframework.data.relational.core.conversion.MappingRelationalConverter.read(MappingRelationalConverter.java:454) ~[spring-data-relational-3.2.0.jar:3.2.0]
	at org.springframework.data.relational.core.conversion.MappingRelationalConverter.readAggregate(MappingRelationalConverter.java:348) ~[spring-data-relational-3.2.0.jar:3.2.0]
	at org.springframework.data.relational.core.conversion.MappingRelationalConverter.readAggregate(MappingRelationalConverter.java:311) ~[spring-data-relational-3.2.0.jar:3.2.0]
	at org.springframework.data.relational.core.conversion.MappingRelationalConverter.read(MappingRelationalConverter.java:298) ~[spring-data-relational-3.2.0.jar:3.2.0]
	at org.springframework.data.relational.core.conversion.MappingRelationalConverter.read(MappingRelationalConverter.java:294) ~[spring-data-relational-3.2.0.jar:3.2.0]
	at org.springframework.data.r2dbc.core.R2dbcEntityTemplate.lambda$getRowsFetchSpec$13(R2dbcEntityTemplate.java:795) ~[spring-data-r2dbc-3.2.0.jar:3.2.0]
	at io.r2dbc.proxy.callback.ResultCallbackHandler.lambda$invoke$0(ResultCallbackHandler.java:92) ~[r2dbc-proxy-1.1.2.RELEASE.jar:1.1.2.RELEASE]
	at io.asyncer.r2dbc.mysql.MySqlResult.lambda$map$1(MySqlResult.java:87) ~[r2dbc-mysql-1.0.5.jar:1.0.5]
	at reactor.core.publisher.FluxHandleFuseable$HandleFuseableSubscriber.onNext(FluxHandleFuseable.java:179) ~[reactor-core-3.6.0.jar:3.6.0]
	at reactor.core.publisher.FluxHandleFuseable$HandleFuseableConditionalSubscriber.onNext(FluxHandleFuseable.java:505) ~[reactor-core-3.6.0.jar:3.6.0]
	at reactor.core.publisher.FluxContextWrite$ContextWriteSubscriber.onNext(FluxContextWrite.java:107) ~[reactor-core-3.6.0.jar:3.6.0]
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Dec 6, 2023
@mp911de
Copy link
Member

mp911de commented Dec 6, 2023

Care to upgrade to Spring Data Relational/R2DBC 3.2.1-SNAPSHOT for both artifacts and retest?

I'm not able to reproduce the issue without further details.

Please provide a minimal yet complete sample that reproduces the problem.
You can share it with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue.

@mp911de mp911de added the status: waiting-for-feedback We need additional information before we can continue label Dec 6, 2023
mp911de added a commit that referenced this issue Dec 6, 2023
Switch to spaces.

See #1690
mp911de added a commit that referenced this issue Dec 6, 2023
Switch to spaces.

See #1690
@shuaqiu
Copy link
Author

shuaqiu commented Dec 6, 2023

r2dbc-test.zip

I extract a test project. You can run the unit test at MemberRepoTest.java to reproduct the problem.

Care to upgrade to Spring Data Relational/R2DBC 3.2.1-SNAPSHOT for both artifacts and retest?

I'm not able to reproduce the issue without further details.

Please provide a minimal yet complete sample that reproduces the problem. You can share it with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Dec 6, 2023
@mp911de
Copy link
Member

mp911de commented Dec 6, 2023

Thanks a lot. The difference is that your entity implements the interface and effectively it isn't a projection.

@mp911de mp911de changed the title "Failed to instantiate IMember using constructor NO_CONSTRUCTOR with arguments" after upgrade from 3.1.5 to 3.2.0 R2dbcEntityTemplate fails to instantiate interface using fluent as(…) projection Dec 6, 2023
@mp911de mp911de added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged status: feedback-provided Feedback has been provided type: bug A general bug labels Dec 6, 2023
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Dec 6, 2023
@mp911de mp911de added the type: regression A regression from a previous release label Dec 6, 2023
@mp911de mp911de added this to the 3.2.1 (2023.1.1) milestone Dec 6, 2023
@mp911de mp911de closed this as completed in eb63036 Dec 6, 2023
mp911de added a commit that referenced this issue Dec 6, 2023
Using as with an interface that is implemented by the entity, we no longer attempt to instantiate the interface bur use the entity type instead.

Closes #1690
@mp911de mp911de removed the status: waiting-for-triage An issue we've not yet triaged label Dec 6, 2023
@shuaqiu
Copy link
Author

shuaqiu commented Dec 7, 2023

Now I have an another question.

For my use case, I should use .as(IMember.class) method as above, or use .map(Function.identity()) as

    public Mono<IMember> findById(final String id) {
        final Query query = Query
            .query(CriteriaBuilder.buildIdQuery(id));
        return entityTemplate.select(MemberBo.class)
            .from(TABLE__MEMBER)
            .matching(query)
            .first()
            .map(Function.identity());
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: regression A regression from a previous release
Projects
None yet
Development

No branches or pull requests

3 participants