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

R2dbcCustomConversions converts LocalDate/LocalDateTime/Instant values to java.util.Date #207

Closed
andriipivovarov opened this issue Oct 7, 2019 · 9 comments
Labels
type: bug A general bug

Comments

@andriipivovarov
Copy link

andriipivovarov commented Oct 7, 2019

Looks like spring data r2dbc converts fields with type Instant to Date and LocalDateTime to Timestamp when i use

        databaseClient
                .insert()
                .into(...)
                .using(...)

and becuase r2dbc-myslq driver haven`t codes for them it leads to issue:

java.lang.IllegalArgumentException: Cannot encode value of type 'class java.util.Date'

	at dev.miku.r2dbc.mysql.codec.DefaultCodecs.encode(DefaultCodecs.java:182)
	at dev.miku.r2dbc.mysql.ParametrizedMySqlStatement.bind(ParametrizedMySqlStatement.java:75)
	at dev.miku.r2dbc.mysql.ParametrizedMySqlStatement.bind(ParametrizedMySqlStatement.java:41)
	at org.springframework.data.r2dbc.core.DefaultDatabaseClient$StatementWrapper.bind(DefaultDatabaseClient.java:1565)
	at org.springframework.data.r2dbc.dialect.IndexedBindMarker.bind(IndexedBindMarker.java:47)
	at org.springframework.data.r2dbc.dialect.Bindings$ValueBinding.apply(Bindings.java:238)
	at org.springframework.data.r2dbc.dialect.Bindings.lambda$apply$1(Bindings.java:122)
	at java.util.LinkedHashMap.forEach(LinkedHashMap.java:684)

From driver mapping guidelines this types shouldn`t have codes: https://github.com/r2dbc/r2dbc-spi/blob/master/r2dbc-spec/src/main/asciidoc/data-types.adoc#datatypes.mapping.datetime

Our libs versions:

  api("org.springframework.data:spring-data-r2dbc:1.0.0.RC1")
  api("io.r2dbc:r2dbc-pool:0.8.0.RC1")
  api("dev.miku:r2dbc-mysql:0.8.0.RC1")
  api("mysql:mysql-connector-java:8.0.13")
@andriipivovarov andriipivovarov changed the title Issue with converting Instant to Date using r2dbc-mysql Drive Issue with converting Instant to Date using r2dbc-mysql driver Oct 7, 2019
@mp911de
Copy link
Member

mp911de commented Oct 7, 2019

That sounds like a bug in Spring Data R2DBC. Can you attach a bit more code that would allow us reproducing the issue?

@mp911de mp911de added the type: bug A general bug label Oct 7, 2019
@mp911de mp911de added the status: waiting-for-feedback We need additional information before we can continue label Oct 23, 2019
@mp911de
Copy link
Member

mp911de commented Oct 23, 2019

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.

@mp911de mp911de closed this as completed Oct 23, 2019
@benarena
Copy link

@mp911de I am also encountering this issue. Here is a small repo that will reproduce the error: https://github.com/benarena/spring-r2dbc-date-error

@mp911de mp911de reopened this May 15, 2020
@mp911de
Copy link
Member

mp911de commented May 15, 2020

Thanks a lot. The issue is caused by Spring Data's default converters that enforce conversion from JSR-310 types to java.util.Date. The fix is to preserve the value as-is so that we skip the conversion.

@mp911de mp911de changed the title Issue with converting Instant to Date using r2dbc-mysql driver R2dbcCustomConversions converts LocalDate/LocalDateTime/Instant values to java.util.Date May 15, 2020
@mp911de mp911de added this to the 1.1.1 (Neumann SR1) milestone May 15, 2020
mp911de added a commit that referenced this issue May 15, 2020
We now prevent converter registrations that enforce a conversion from JSR-310 types to java.util.Date. R2DBC drivers use natively JSR-310 types and some of them don't implement java.util.Date at all.
mp911de added a commit that referenced this issue May 15, 2020
We now prevent converter registrations that enforce a conversion from JSR-310 types to java.util.Date. R2DBC drivers use natively JSR-310 types and some of them don't implement java.util.Date at all.
@mp911de
Copy link
Member

mp911de commented May 15, 2020

That's fixed now.

@mp911de mp911de closed this as completed May 15, 2020
@mp911de mp911de removed the status: waiting-for-feedback We need additional information before we can continue label May 15, 2020
@alfikr
Copy link

alfikr commented Jul 12, 2021

i have the same problem now

reactor.core.Exceptions$ErrorCallbackNotImplemented: java.lang.IllegalArgumentException: No encoder for class java.time.ZonedDateTime (parameter at index 1) 
Caused by: java.lang.IllegalArgumentException: No encoder for class java.time.ZonedDateTime (parameter at index 1) 
	at org.mariadb.r2dbc.MariadbClientParameterizedQueryStatement.bind(MariadbClientParameterizedQueryStatement.java:93) ~[r2dbc-mariadb-1.0.1.jar:1.0.1]
	at org.mariadb.r2dbc.MariadbClientParameterizedQueryStatement.bind(MariadbClientParameterizedQueryStatement.java:34) ~[r2dbc-mariadb-1.0.1.jar:1.0.1]
	at org.springframework.r2dbc.core.DefaultDatabaseClient$StatementWrapper.bind(DefaultDatabaseClient.java:544) ~[spring-r2dbc-5.3.8.jar:5.3.8]
	at org.springframework.r2dbc.core.binding.IndexedBindMarkers$IndexedBindMarker.bind(IndexedBindMarkers.java:86) ~[spring-r2dbc-5.3.8.jar:5.3.8]
	at org.springframework.r2dbc.core.binding.Bindings$ValueBinding.apply(Bindings.java:216) ~[spring-r2dbc-5.3.8.jar:5.3.8]
	at org.springframework.r2dbc.core.binding.Bindings.lambda$apply$1(Bindings.java:93) ~[spring-r2dbc-5.3.8.jar:5.3.8]
	at java.base/java.util.LinkedHashMap.forEach(LinkedHashMap.java:684) ~[na:na]
	at org.springframework.r2dbc.core.binding.Bindings.apply(Bindings.java:93) ~[spring-r2dbc-5.3.8.jar:5.3.8]
	at org.springframework.data.r2dbc.core.DefaultStatementMapper$DefaultPreparedOperation.bindTo(DefaultStatementMapper.java:354) ~[spring-data-r2dbc-1.3.2.jar:1.3.2]
	at org.springframework.r2dbc.core.DefaultDatabaseClient$DefaultGenericExecuteSpec.lambda$execute$2(DefaultDatabaseClient.java:334) ~[spring-r2dbc-5.3.8.jar:5.3.8]
	at org.springframework.r2dbc.core.DefaultDatabaseClient$DefaultGenericExecuteSpec.lambda$execute$3(DefaultDatabaseClient.java:374) ~[spring-r2dbc-5.3.8.jar:5.3.8]
	at org.springframework.r2dbc.core.ConnectionFunction.apply(ConnectionFunction.java:46) ~[spring-r2dbc-5.3.8.jar:5.3.8]
	at org.springframework.r2dbc.core.ConnectionFunction.apply(ConnectionFunction.java:31) ~[spring-r2dbc-5.3.8.jar:5.3.8]
	at org.springframework.r2dbc.core.DefaultFetchSpec.lambda$all$2(DefaultFetchSpec.java:88) ~[spring-r2dbc-5.3.8.jar:5.3.8]
	at org.springframework.r2dbc.core.ConnectionFunction.apply(ConnectionFunction.java:46) ~[spring-r2dbc-5.3.8.jar:5.3.8]
	at org.springframework.r2dbc.core.ConnectionFunction.apply(ConnectionFunction.java:31) ~[spring-r2dbc-5.3.8.jar:5.3.8]
	at org.springframework.r2dbc.core.DefaultDatabaseClient.lambda$inConnectionMany$6(DefaultDatabaseClient.java:138) ~[spring-r2dbc-5.3.8.jar:5.3.8]
	at reactor.core.publisher.FluxUsingWhen.deriveFluxFromResource(FluxUsingWhen.java:119) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.FluxUsingWhen.access$000(FluxUsingWhen.java:53) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.FluxUsingWhen$ResourceSubscriber.onNext(FluxUsingWhen.java:194) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.FluxMap$MapSubscriber.onNext(FluxMap.java:120) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.FluxOnErrorResume$ResumeSubscriber.onNext(FluxOnErrorResume.java:79) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.FluxOnErrorResume$ResumeSubscriber.onNext(FluxOnErrorResume.java:79) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.FluxRetry$RetrySubscriber.onNext(FluxRetry.java:86) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.FluxPeekFuseable$PeekFuseableSubscriber.onNext(FluxPeekFuseable.java:210) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.Operators$MonoSubscriber.complete(Operators.java:1815) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.MonoFlatMap$FlatMapInner.onNext(MonoFlatMap.java:249) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.FluxOnErrorResume$ResumeSubscriber.onNext(FluxOnErrorResume.java:79) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.MonoIgnoreThen$ThenIgnoreMain.complete(MonoIgnoreThen.java:284) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.MonoIgnoreThen$ThenIgnoreMain.onNext(MonoIgnoreThen.java:187) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.MonoIgnoreThen$ThenIgnoreMain.subscribeNext(MonoIgnoreThen.java:232) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.MonoIgnoreThen$ThenIgnoreMain.onComplete(MonoIgnoreThen.java:203) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.MonoIgnoreElements$IgnoreElementsSubscriber.onComplete(MonoIgnoreElements.java:88) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.FluxHandleFuseable$HandleFuseableSubscriber.onNext(FluxHandleFuseable.java:201) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.Operators$ScalarSubscription.request(Operators.java:2397) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.FluxHandleFuseable$HandleFuseableSubscriber.request(FluxHandleFuseable.java:250) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.MonoIgnoreElements$IgnoreElementsSubscriber.onSubscribe(MonoIgnoreElements.java:71) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.FluxHandleFuseable$HandleFuseableSubscriber.onSubscribe(FluxHandleFuseable.java:154) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.FluxJust.subscribe(FluxJust.java:68) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.Mono.subscribe(Mono.java:4150) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.MonoIgnoreThen$ThenIgnoreMain.subscribeNext(MonoIgnoreThen.java:255) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.MonoIgnoreThen.subscribe(MonoIgnoreThen.java:51) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:64) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.MonoFlatMap$FlatMapMain.onNext(MonoFlatMap.java:157) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.FluxPeek$PeekSubscriber.onNext(FluxPeek.java:199) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.FluxPeek$PeekSubscriber.onNext(FluxPeek.java:199) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.pool.AbstractPool$Borrower.deliver(AbstractPool.java:436) ~[reactor-pool-0.2.5.jar:0.2.5]
	at reactor.pool.SimpleDequePool.lambda$drainLoop$9(SimpleDequePool.java:391) ~[reactor-pool-0.2.5.jar:0.2.5]
	at reactor.core.publisher.FluxDoOnEach$DoOnEachSubscriber.onNext(FluxDoOnEach.java:154) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.FluxMap$MapConditionalSubscriber.onNext(FluxMap.java:220) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.FluxOnErrorResume$ResumeSubscriber.onNext(FluxOnErrorResume.java:79) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.Operators$MonoSubscriber.complete(Operators.java:1815) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.MonoFlatMap$FlatMapInner.onNext(MonoFlatMap.java:249) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.FluxOnErrorResume$ResumeSubscriber.onNext(FluxOnErrorResume.java:79) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.MonoIgnoreThen$ThenIgnoreMain.complete(MonoIgnoreThen.java:284) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.MonoIgnoreThen$ThenIgnoreMain.onNext(MonoIgnoreThen.java:187) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.MonoIgnoreThen$ThenIgnoreMain.subscribeNext(MonoIgnoreThen.java:232) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.MonoIgnoreThen.subscribe(MonoIgnoreThen.java:51) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:64) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.MonoFlatMap$FlatMapMain.onNext(MonoFlatMap.java:157) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.FluxMap$MapSubscriber.onNext(FluxMap.java:120) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.MonoDelayUntil$DelayUntilCoordinator.complete(MonoDelayUntil.java:418) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.MonoDelayUntil$DelayUntilTrigger.onComplete(MonoDelayUntil.java:531) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.MonoIgnoreThen$ThenIgnoreMain.complete(MonoIgnoreThen.java:285) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.MonoIgnoreThen$ThenIgnoreMain.onNext(MonoIgnoreThen.java:187) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.MonoIgnoreThen$ThenIgnoreMain.subscribeNext(MonoIgnoreThen.java:232) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.MonoIgnoreThen$ThenIgnoreMain.onComplete(MonoIgnoreThen.java:203) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.FluxPeek$PeekSubscriber.onComplete(FluxPeek.java:259) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.FluxPeek$PeekSubscriber.onComplete(FluxPeek.java:259) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.FluxPeek$PeekSubscriber.onComplete(FluxPeek.java:259) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.FluxCreate$BaseSink.complete(FluxCreate.java:439) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.FluxCreate$BufferAsyncSink.drain(FluxCreate.java:784) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.FluxCreate$BufferAsyncSink.complete(FluxCreate.java:732) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.FluxCreate$SerializedFluxSink.drainLoop(FluxCreate.java:240) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.FluxCreate$SerializedFluxSink.next(FluxCreate.java:169) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.LambdaMonoSubscriber.onNext(LambdaMonoSubscriber.java:171) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.MonoNext$NextSubscriber.onNext(MonoNext.java:82) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.FluxHandle$HandleSubscriber.onNext(FluxHandle.java:118) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.FluxCreate$BufferAsyncSink.drain(FluxCreate.java:793) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.FluxCreate$BufferAsyncSink.next(FluxCreate.java:718) ~[reactor-core-3.4.7.jar:3.4.7]
	at reactor.core.publisher.FluxCreate$SerializedFluxSink.next(FluxCreate.java:154) ~[reactor-core-3.4.7.jar:3.4.7]
	at org.mariadb.r2dbc.client.MariadbPacketDecoder.handleBuffer(MariadbPacketDecoder.java:110) ~[r2dbc-mariadb-1.0.1.jar:1.0.1]
	at org.mariadb.r2dbc.client.MariadbPacketDecoder.decode(MariadbPacketDecoder.java:85) ~[r2dbc-mariadb-1.0.1.jar:1.0.1]
	at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:507) ~[netty-codec-4.1.65.Final.jar:4.1.65.Final]
	at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:446) ~[netty-codec-4.1.65.Final.jar:4.1.65.Final]
	at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:276) ~[netty-codec-4.1.65.Final.jar:4.1.65.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) ~[netty-transport-4.1.65.Final.jar:4.1.65.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) ~[netty-transport-4.1.65.Final.jar:4.1.65.Final]
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) ~[netty-transport-4.1.65.Final.jar:4.1.65.Final]
	at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410) ~[netty-transport-4.1.65.Final.jar:4.1.65.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) ~[netty-transport-4.1.65.Final.jar:4.1.65.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) ~[netty-transport-4.1.65.Final.jar:4.1.65.Final]
	at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919) ~[netty-transport-4.1.65.Final.jar:4.1.65.Final]
	at io.netty.channel.epoll.AbstractEpollStreamChannel$EpollStreamUnsafe.epollInReady(AbstractEpollStreamChannel.java:795) ~[netty-transport-native-epoll-4.1.65.Final-linux-x86_64.jar:4.1.65.Final]
	at io.netty.channel.epoll.EpollEventLoop.processReady(EpollEventLoop.java:480) ~[netty-transport-native-epoll-4.1.65.Final-linux-x86_64.jar:4.1.65.Final]
	at io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:378) ~[netty-transport-native-epoll-4.1.65.Final-linux-x86_64.jar:4.1.65.Final]
	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989) ~[netty-common-4.1.65.Final.jar:4.1.65.Final]
	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.65.Final.jar:4.1.65.Final]
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-common-4.1.65.Final.jar:4.1.65.Final]
	at java.base/java.lang.Thread.run(Thread.java:829) ~[na:na]

@mp911de
Copy link
Member

mp911de commented Jul 12, 2021

@alfikr care to elaborate how conversion from LocalDate to Date relates to ZonedDateTime?

@alfikr
Copy link

alfikr commented Jul 13, 2021

@alfikr care to elaborate how conversion from LocalDate to Date relates to ZonedDateTime?

there's error too. I've try to change to any other format. java.sql.Date still error

@funky-eyes
Copy link

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

5 participants