Skip to content

Access to identifier property not guarded properly #711

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

Closed
MugenTwo opened this issue Jan 19, 2022 · 4 comments
Closed

Access to identifier property not guarded properly #711

MugenTwo opened this issue Jan 19, 2022 · 4 comments
Assignees
Labels
type: bug A general bug

Comments

@MugenTwo
Copy link

Hi!

As mentioned in the title, Persistable does not seem to be working correctly with R2DBC.
This interface has 2 methods: getId() and isNew(). The latter seems to be working fine.

But I don't think getId() is working fine as I am get the following error whenever I use the save() method of the ReactiveCrudRepository:

at org.springframework.data.mapping.PersistentEntity.getRequiredIdProperty(PersistentEntity.java:106)

My entity is as follows:

import lombok.AccessLevel;
import lombok.Data;
import lombok.experimental.FieldDefaults;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Transient;
import org.springframework.data.domain.Persistable;

@Data
@FieldDefaults(level = AccessLevel.PRIVATE)
public class Foo implements Persistable<String> {

    String x;
    String y;
    String z;

    @Transient
    private boolean isNew;

    @Id
    @Transient
    @Override
    public String getId() {
        return x + "-" + y;
    }

    @Override
    public boolean isNew() {
        return isNew;
    }

}
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jan 19, 2022
@mp911de mp911de self-assigned this Jan 20, 2022
@mp911de mp911de added type: bug A general bug status: waiting-for-triage An issue we've not yet triaged and removed status: waiting-for-triage An issue we've not yet triaged type: bug A general bug labels Jan 20, 2022
@mp911de
Copy link
Member

mp911de commented Jan 20, 2022

Care to post the full stack trace?

Inserts can work if the entity doesn't expose an @Id column, however, updates require an Id column as the target SQL statement cannot work if the identifier column name is not specified.

@mp911de mp911de added the status: waiting-for-feedback We need additional information before we can continue label Jan 20, 2022
mp911de added a commit that referenced this issue Jan 20, 2022
We now check in all places where we optionally use the Id property that an entity actually has an Id property and fall back leniently if the entity doesn't have an identifier property.

Also, we use IdentifierAccessor consistently if the property is an identifier property.

See #711
mp911de added a commit that referenced this issue Jan 20, 2022
We now check in all places where we optionally use the Id property that an entity actually has an Id property and fall back leniently if the entity doesn't have an identifier property.

Also, we use IdentifierAccessor consistently if the property is an identifier property.

See #711
mp911de added a commit that referenced this issue Jan 20, 2022
We now check in all places where we optionally use the Id property that an entity actually has an Id property and fall back leniently if the entity doesn't have an identifier property.

Also, we use IdentifierAccessor consistently if the property is an identifier property.

See #711
mp911de added a commit that referenced this issue Jan 20, 2022
We now check in all places where we optionally use the Id property that an entity actually has an Id property and fall back leniently if the entity doesn't have an identifier property.

Also, we use IdentifierAccessor consistently if the property is an identifier property.

See #711
@MugenTwo
Copy link
Author

Here is the stack trace:

Original Stack Trace:
                at org.springframework.data.mapping.PersistentEntity.getRequiredIdProperty(PersistentEntity.java:106) ~[spring-data-commons-2.5.7.jar:2.5.7]
                at org.springframework.data.r2dbc.convert.MappingR2dbcConverter.lambda$populateIdIfNecessary$1(MappingR2dbcConverter.java:606) ~[spring-data-r2dbc-1.3.7.jar:1.3.7]
                at dev.miku.r2dbc.mysql.MySqlResult.lambda$map$2(MySqlResult.java:97) ~[r2dbc-mysql-0.8.2.RELEASE.jar:0.8.2.RELEASE]
                at reactor.core.publisher.FluxMap$MapSubscriber.onNext(FluxMap.java:106) ~[reactor-core-3.4.13.jar:3.4.13]
                at org.springframework.cloud.sleuth.instrument.reactor.ScopePassingSpanSubscriber.onNext(ScopePassingSpanSubscriber.java:88) ~[spring-cloud-sleuth-instrumentation-3.0.5.jar:3.0.5]
                at reactor.core.publisher.FluxPeek$PeekSubscriber.onNext(FluxPeek.java:200) ~[reactor-core-3.4.13.jar:3.4.13]
                at reactor.core.publisher.Operators$MonoSubscriber.complete(Operators.java:1816) ~[reactor-core-3.4.13.jar:3.4.13]
                at reactor.core.publisher.NextProcessor.tryEmitValue(NextProcessor.java:301) ~[reactor-core-3.4.13.jar:3.4.13]
                at reactor.core.publisher.NextProcessor.onNext(NextProcessor.java:241) ~[reactor-core-3.4.13.jar:3.4.13]
                at dev.miku.r2dbc.mysql.MySqlResult.lambda$null$3(MySqlResult.java:114) ~[r2dbc-mysql-0.8.2.RELEASE.jar:0.8.2.RELEASE]
                at reactor.core.publisher.LambdaSubscriber.onNext(LambdaSubscriber.java:160) ~[reactor-core-3.4.13.jar:3.4.13]
                at org.springframework.cloud.sleuth.instrument.reactor.ScopePassingSpanSubscriber.onNext(ScopePassingSpanSubscriber.java:88) ~[spring-cloud-sleuth-instrumentation-3.0.5.jar:3.0.5]
                at reactor.core.publisher.FluxWindowPredicate$WindowFlux.drainRegular(FluxWindowPredicate.java:668) ~[reactor-core-3.4.13.jar:3.4.13]
                at reactor.core.publisher.FluxWindowPredicate$WindowFlux.drain(FluxWindowPredicate.java:746) ~[reactor-core-3.4.13.jar:3.4.13]
                at reactor.core.publisher.FluxWindowPredicate$WindowFlux.onNext(FluxWindowPredicate.java:788) ~[reactor-core-3.4.13.jar:3.4.13]
                at reactor.core.publisher.FluxWindowPredicate$WindowPredicateMain.onNext(FluxWindowPredicate.java:239) ~[reactor-core-3.4.13.jar:3.4.13]
                at reactor.core.publisher.FluxHandleFuseable$HandleFuseableSubscriber.onNext(FluxHandleFuseable.java:184) ~[reactor-core-3.4.13.jar:3.4.13]
                at org.springframework.cloud.sleuth.instrument.reactor.ScopePassingSpanSubscriber.onNext(ScopePassingSpanSubscriber.java:88) ~[spring-cloud-sleuth-instrumentation-3.0.5.jar:3.0.5]
                at reactor.core.publisher.FluxContextWrite$ContextWriteSubscriber.onNext(FluxContextWrite.java:107) ~[reactor-core-3.4.13.jar:3.4.13]
                at dev.miku.r2dbc.mysql.util.DiscardOnCancelSubscriber.onNext(DiscardOnCancelSubscriber.java:70) ~[r2dbc-mysql-0.8.2.RELEASE.jar:0.8.2.RELEASE]
                at reactor.core.publisher.FluxPeekFuseable$PeekConditionalSubscriber.onNext(FluxPeekFuseable.java:854) ~[reactor-core-3.4.13.jar:3.4.13]
                at reactor.core.publisher.MonoFlatMapMany$FlatMapManyInner.onNext(MonoFlatMapMany.java:250) ~[reactor-core-3.4.13.jar:3.4.13]
                at org.springframework.cloud.sleuth.instrument.reactor.ScopePassingSpanSubscriber.onNext(ScopePassingSpanSubscriber.java:88) ~[spring-cloud-sleuth-instrumentation-3.0.5.jar:3.0.5]
                at reactor.core.publisher.FluxPeek$PeekSubscriber.onNext(FluxPeek.java:200) ~[reactor-core-3.4.13.jar:3.4.13]
                at reactor.core.publisher.FluxHandle$HandleSubscriber.onNext(FluxHandle.java:119) ~[reactor-core-3.4.13.jar:3.4.13]
                at org.springframework.cloud.sleuth.instrument.reactor.ScopePassingSpanSubscriber.onNext(ScopePassingSpanSubscriber.java:88) ~[spring-cloud-sleuth-instrumentation-3.0.5.jar:3.0.5]
                at reactor.core.publisher.FluxPeek$PeekSubscriber.onNext(FluxPeek.java:200) ~[reactor-core-3.4.13.jar:3.4.13]
                at reactor.core.publisher.EmitterProcessor.drain(EmitterProcessor.java:491) ~[reactor-core-3.4.13.jar:3.4.13]
                at reactor.core.publisher.EmitterProcessor.tryEmitNext(EmitterProcessor.java:299) ~[reactor-core-3.4.13.jar:3.4.13]
                at reactor.core.publisher.InternalManySink.emitNext(InternalManySink.java:27) ~[reactor-core-3.4.13.jar:3.4.13]
                at reactor.core.publisher.EmitterProcessor.onNext(EmitterProcessor.java:265) ~[reactor-core-3.4.13.jar:3.4.13]
                at dev.miku.r2dbc.mysql.client.ReactorNettyClient$ResponseSink.next(ReactorNettyClient.java:340) ~[r2dbc-mysql-0.8.2.RELEASE.jar:0.8.2.RELEASE]
                at dev.miku.r2dbc.mysql.client.ReactorNettyClient.lambda$new$0(ReactorNettyClient.java:103) ~[r2dbc-mysql-0.8.2.RELEASE.jar:0.8.2.RELEASE]
                at reactor.core.publisher.FluxPeek$PeekSubscriber.onNext(FluxPeek.java:185) [reactor-core-3.4.13.jar:3.4.13]
                at reactor.netty.channel.FluxReceive.drainReceiver(FluxReceive.java:279) [reactor-netty-core-1.0.14.jar:1.0.14]
                at reactor.netty.channel.FluxReceive.onInboundNext(FluxReceive.java:388) [reactor-netty-core-1.0.14.jar:1.0.14]
                at reactor.netty.channel.ChannelOperations.onInboundNext(ChannelOperations.java:404) [reactor-netty-core-1.0.14.jar:1.0.14]
                at reactor.netty.channel.ChannelOperationsHandler.channelRead(ChannelOperationsHandler.java:93) [reactor-netty-core-1.0.14.jar:1.0.14]
                at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) [netty-transport-4.1.72.Final.jar:4.1.72.Final]
                at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) [netty-transport-4.1.72.Final.jar:4.1.72.Final]
                at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) [netty-transport-4.1.72.Final.jar:4.1.72.Final]
                at dev.miku.r2dbc.mysql.client.MessageDuplexCodec.handleDecoded(MessageDuplexCodec.java:187) [r2dbc-mysql-0.8.2.RELEASE.jar:0.8.2.RELEASE]
                at dev.miku.r2dbc.mysql.client.MessageDuplexCodec.channelRead(MessageDuplexCodec.java:95) [r2dbc-mysql-0.8.2.RELEASE.jar:0.8.2.RELEASE]
                at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) [netty-transport-4.1.72.Final.jar:4.1.72.Final]
                at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) [netty-transport-4.1.72.Final.jar:4.1.72.Final]
                at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) [netty-transport-4.1.72.Final.jar:4.1.72.Final]
                at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:324) [netty-codec-4.1.72.Final.jar:4.1.72.Final]
                at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:296) [netty-codec-4.1.72.Final.jar:4.1.72.Final]
                at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) [netty-transport-4.1.72.Final.jar:4.1.72.Final]
                at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) [netty-transport-4.1.72.Final.jar:4.1.72.Final]
                at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) [netty-transport-4.1.72.Final.jar:4.1.72.Final]
                at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410) [netty-transport-4.1.72.Final.jar:4.1.72.Final]
                at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) [netty-transport-4.1.72.Final.jar:4.1.72.Final]
                at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) [netty-transport-4.1.72.Final.jar:4.1.72.Final]
                at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919) [netty-transport-4.1.72.Final.jar:4.1.72.Final]
                at io.netty.channel.epoll.AbstractEpollStreamChannel$EpollStreamUnsafe.epollInReady(AbstractEpollStreamChannel.java:795) [netty-transport-classes-epoll-4.1.72.Final.jar:4.1.72.Final]
                at io.netty.channel.epoll.EpollEventLoop.processReady(EpollEventLoop.java:480) [netty-transport-classes-epoll-4.1.72.Final.jar:4.1.72.Final]
                at io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:378) [netty-transport-classes-epoll-4.1.72.Final.jar:4.1.72.Final]
                at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986) [netty-common-4.1.72.Final.jar:4.1.72.Final]
                at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) [netty-common-4.1.72.Final.jar:4.1.72.Final]
                at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) [netty-common-4.1.72.Final.jar:4.1.72.Final]
                at java.lang.Thread.run(Thread.java:834) [?:?]

@MugenTwo
Copy link
Author

From what I can see the Entity is being inserted in the Database, but after that I see this error.

@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 Jan 21, 2022
@mp911de
Copy link
Member

mp911de commented Jan 24, 2022

Thanks a lot. The issue from the stack trace is fixed and you might want to retest against snapshots, specifically 1.4.2-SNAPSHOT

@mp911de mp911de closed this as completed Jan 24, 2022
@mp911de mp911de added this to the 1.3.9 (2021.0.9) milestone Jan 24, 2022
@mp911de mp911de added type: bug A general bug and removed status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged labels Jan 24, 2022
@mp911de mp911de changed the title Persistable<ID> interface not working correctly with Spring R2DBC Access to identifier property not guarded propertly Jan 24, 2022
@mp911de mp911de changed the title Access to identifier property not guarded propertly Access to identifier property not guarded properly Jan 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants