Spring 数据 r2dbc 错误 - 截断了不正确的 DOUBLE 值
Spring data r2dbc error - Truncated incorrect DOUBLE value
我正在使用 Spring 数据 r2dbc 并遇到一个奇怪的问题。
implementation 'org.springframework.boot:spring-boot-starter-data-r2dbc'
runtimeOnly 'dev.miku:r2dbc-mysql'
runtimeOnly 'mysql:mysql-connector-java'
更新查询出错。
@Modifying
@Query("UPDATE appt SET notes = :newNotes WHERE appt_id = :apptId AND org_id = :orgId")
Mono<Integer> updateAppt(long apptId, int orgId, String newNotes);
错误:-
Caused by: io.r2dbc.spi.R2dbcNonTransientResourceException: Truncated incorrect DOUBLE value: 'Test create Appointment - Updated'
at dev.miku.r2dbc.mysql.ExceptionFactory.mappingSqlState(ExceptionFactory.java:115) ~[r2dbc-mysql-0.8.2.RELEASE.jar:0.8.2.RELEASE]
Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException:
Error has been observed at the following site(s):
|_ checkpoint ⇢ SQL "UPDATE appt SET notes = :newNotes WHERE appt_id = :apptId AND org_id = :orgId" [DatabaseClient]
Stack trace:
at dev.miku.r2dbc.mysql.ExceptionFactory.mappingSqlState(ExceptionFactory.java:115) ~[r2dbc-mysql-0.8.2.RELEASE.jar:0.8.2.RELEASE]
at dev.miku.r2dbc.mysql.ExceptionFactory.createException(ExceptionFactory.java:102) ~[r2dbc-mysql-0.8.2.RELEASE.jar:0.8.2.RELEASE]
at dev.miku.r2dbc.mysql.TextQueryHandler.accept(QueryFlow.java:317) ~[r2dbc-mysql-0.8.2.RELEASE.jar:0.8.2.RELEASE]
at dev.miku.r2dbc.mysql.TextQueryHandler.accept(QueryFlow.java:292) ~[r2dbc-mysql-0.8.2.RELEASE.jar:0.8.2.RELEASE]
at reactor.core.publisher.FluxHandleFuseable$HandleFuseableSubscriber.onNext(FluxHandleFuseable.java:169) ~[reactor-core-3.4.2.jar:3.4.2]
at org.springframework.cloud.sleuth.instrument.reactor.ScopePassingSpanSubscriber.onNext(ScopePassingSpanSubscriber.java:88) ~[spring-cloud-sleuth-instrumentation-3.0.2-SNAPSHOT.jar:3.0.2-SNAPSHOT]
at reactor.core.publisher.FluxContextWrite$ContextWriteSubscriber.onNext(FluxContextWrite.java:107) ~[reactor-core-3.4.2.jar:3.4.2]
at dev.miku.r2dbc.mysql.util.DiscardOnCancelSubscriber.onNext(DiscardOnCancelSubscriber.java:70) ~[r2dbc-mysql-0.8.2.RELEASE.jar:0.8.2.RELEASE]
at org.springframework.cloud.sleuth.instrument.reactor.ScopePassingSpanSubscriber.onNext(ScopePassingSpanSubscriber.java:88) ~[spring-cloud-sleuth-instrumentation-3.0.2-SNAPSHOT.jar:3.0.2-SNAPSHOT]
at reactor.core.publisher.FluxPeek$PeekSubscriber.onNext(FluxPeek.java:199) ~[reactor-core-3.4.2.jar:3.4.2]
at org.springframework.cloud.sleuth.instrument.reactor.ScopePassingSpanSubscriber.onNext(ScopePassingSpanSubscriber.java:88) ~[spring-cloud-sleuth-instrumentation-3.0.2-SNAPSHOT.jar:3.0.2-SNAPSHOT]
at reactor.core.publisher.MonoFlatMapMany$FlatMapManyInner.onNext(MonoFlatMapMany.java:250) ~[reactor-core-3.4.2.jar:3.4.2]
at org.springframework.cloud.sleuth.instrument.reactor.ScopePassingSpanSubscriber.onNext(ScopePassingSpanSubscriber.java:88) ~[spring-cloud-sleuth-instrumentation-3.0.2-SNAPSHOT.jar:3.0.2-SNAPSHOT]
at reactor.core.publisher.FluxPeek$PeekSubscriber.onNext(FluxPeek.java:199) ~[reactor-core-3.4.2.jar:3.4.2]
at org.springframework.cloud.sleuth.instrument.reactor.ScopePassingSpanSubscriber.onNext(ScopePassingSpanSubscriber.java:88) ~[spring-cloud-sleuth-instrumentation-3.0.2-SNAPSHOT.jar:3.0.2-SNAPSHOT]
at reactor.core.publisher.FluxHandle$HandleSubscriber.onNext(FluxHandle.java:118) ~[reactor-core-3.4.2.jar:3.4.2]
at org.springframework.cloud.sleuth.instrument.reactor.ScopePassingSpanSubscriber.onNext(ScopePassingSpanSubscriber.java:88) ~[spring-cloud-sleuth-instrumentation-3.0.2-SNAPSHOT.jar:3.0.2-SNAPSHOT]
at reactor.core.publisher.FluxPeek$PeekSubscriber.onNext(FluxPeek.java:199) ~[reactor-core-3.4.2.jar:3.4.2]
通过 SQL 工作台查询工作正常。
UPDATE appt SET notes = 'Test create Appointment - Updated' WHERE appt_id = 1 AND org_id = 2;
请注意 Spring Data R2DBC 文档中解释 Query Methods 时的第二个信息提示:
R2DBC repositories internally bind parameters to placeholders with Statement.bind(…)
by index.
请尝试将您的方法定义为:
@Modifying
@Query("UPDATE appt SET notes = :newNotes WHERE appt_id = :apptId AND org_id = :orgId")
Mono<Integer> updateAppt(String newNotes, long apptId, int orgId);
请注意参数顺序的变化。
MySQL 显然是在抱怨将值 'Test create Appointment - Updated'
用作数字。
我正在使用 Spring 数据 r2dbc 并遇到一个奇怪的问题。
implementation 'org.springframework.boot:spring-boot-starter-data-r2dbc'
runtimeOnly 'dev.miku:r2dbc-mysql'
runtimeOnly 'mysql:mysql-connector-java'
更新查询出错。
@Modifying
@Query("UPDATE appt SET notes = :newNotes WHERE appt_id = :apptId AND org_id = :orgId")
Mono<Integer> updateAppt(long apptId, int orgId, String newNotes);
错误:-
Caused by: io.r2dbc.spi.R2dbcNonTransientResourceException: Truncated incorrect DOUBLE value: 'Test create Appointment - Updated'
at dev.miku.r2dbc.mysql.ExceptionFactory.mappingSqlState(ExceptionFactory.java:115) ~[r2dbc-mysql-0.8.2.RELEASE.jar:0.8.2.RELEASE]
Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException:
Error has been observed at the following site(s):
|_ checkpoint ⇢ SQL "UPDATE appt SET notes = :newNotes WHERE appt_id = :apptId AND org_id = :orgId" [DatabaseClient]
Stack trace:
at dev.miku.r2dbc.mysql.ExceptionFactory.mappingSqlState(ExceptionFactory.java:115) ~[r2dbc-mysql-0.8.2.RELEASE.jar:0.8.2.RELEASE]
at dev.miku.r2dbc.mysql.ExceptionFactory.createException(ExceptionFactory.java:102) ~[r2dbc-mysql-0.8.2.RELEASE.jar:0.8.2.RELEASE]
at dev.miku.r2dbc.mysql.TextQueryHandler.accept(QueryFlow.java:317) ~[r2dbc-mysql-0.8.2.RELEASE.jar:0.8.2.RELEASE]
at dev.miku.r2dbc.mysql.TextQueryHandler.accept(QueryFlow.java:292) ~[r2dbc-mysql-0.8.2.RELEASE.jar:0.8.2.RELEASE]
at reactor.core.publisher.FluxHandleFuseable$HandleFuseableSubscriber.onNext(FluxHandleFuseable.java:169) ~[reactor-core-3.4.2.jar:3.4.2]
at org.springframework.cloud.sleuth.instrument.reactor.ScopePassingSpanSubscriber.onNext(ScopePassingSpanSubscriber.java:88) ~[spring-cloud-sleuth-instrumentation-3.0.2-SNAPSHOT.jar:3.0.2-SNAPSHOT]
at reactor.core.publisher.FluxContextWrite$ContextWriteSubscriber.onNext(FluxContextWrite.java:107) ~[reactor-core-3.4.2.jar:3.4.2]
at dev.miku.r2dbc.mysql.util.DiscardOnCancelSubscriber.onNext(DiscardOnCancelSubscriber.java:70) ~[r2dbc-mysql-0.8.2.RELEASE.jar:0.8.2.RELEASE]
at org.springframework.cloud.sleuth.instrument.reactor.ScopePassingSpanSubscriber.onNext(ScopePassingSpanSubscriber.java:88) ~[spring-cloud-sleuth-instrumentation-3.0.2-SNAPSHOT.jar:3.0.2-SNAPSHOT]
at reactor.core.publisher.FluxPeek$PeekSubscriber.onNext(FluxPeek.java:199) ~[reactor-core-3.4.2.jar:3.4.2]
at org.springframework.cloud.sleuth.instrument.reactor.ScopePassingSpanSubscriber.onNext(ScopePassingSpanSubscriber.java:88) ~[spring-cloud-sleuth-instrumentation-3.0.2-SNAPSHOT.jar:3.0.2-SNAPSHOT]
at reactor.core.publisher.MonoFlatMapMany$FlatMapManyInner.onNext(MonoFlatMapMany.java:250) ~[reactor-core-3.4.2.jar:3.4.2]
at org.springframework.cloud.sleuth.instrument.reactor.ScopePassingSpanSubscriber.onNext(ScopePassingSpanSubscriber.java:88) ~[spring-cloud-sleuth-instrumentation-3.0.2-SNAPSHOT.jar:3.0.2-SNAPSHOT]
at reactor.core.publisher.FluxPeek$PeekSubscriber.onNext(FluxPeek.java:199) ~[reactor-core-3.4.2.jar:3.4.2]
at org.springframework.cloud.sleuth.instrument.reactor.ScopePassingSpanSubscriber.onNext(ScopePassingSpanSubscriber.java:88) ~[spring-cloud-sleuth-instrumentation-3.0.2-SNAPSHOT.jar:3.0.2-SNAPSHOT]
at reactor.core.publisher.FluxHandle$HandleSubscriber.onNext(FluxHandle.java:118) ~[reactor-core-3.4.2.jar:3.4.2]
at org.springframework.cloud.sleuth.instrument.reactor.ScopePassingSpanSubscriber.onNext(ScopePassingSpanSubscriber.java:88) ~[spring-cloud-sleuth-instrumentation-3.0.2-SNAPSHOT.jar:3.0.2-SNAPSHOT]
at reactor.core.publisher.FluxPeek$PeekSubscriber.onNext(FluxPeek.java:199) ~[reactor-core-3.4.2.jar:3.4.2]
通过 SQL 工作台查询工作正常。
UPDATE appt SET notes = 'Test create Appointment - Updated' WHERE appt_id = 1 AND org_id = 2;
请注意 Spring Data R2DBC 文档中解释 Query Methods 时的第二个信息提示:
R2DBC repositories internally bind parameters to placeholders with
Statement.bind(…)
by index.
请尝试将您的方法定义为:
@Modifying
@Query("UPDATE appt SET notes = :newNotes WHERE appt_id = :apptId AND org_id = :orgId")
Mono<Integer> updateAppt(String newNotes, long apptId, int orgId);
请注意参数顺序的变化。
MySQL 显然是在抱怨将值 'Test create Appointment - Updated'
用作数字。