【问题标题】:Spring data r2dbc error - Truncated incorrect DOUBLE valueSpring数据r2dbc错误-截断不正确的DOUBLE值
【发布时间】:2021-05-13 14:16:07
【问题描述】:

我正在使用 Spring data 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 bench 进行查询工作正常。

UPDATE appt SET notes = 'Test create Appointment - Updated' WHERE appt_id = 1 AND org_id = 2;

【问题讨论】:

  • 您的实体看起来如何?
  • 我没有看到实体有任何问题。它通过 JPA 实体工作正常,但不适用于查询。为任何更新查询获取相同的错误。看起来像 Spring data r2dbc 中的一个错误。
  • R2DBC 不支持 JPA 注释,因此实体必须看起来非常不同。
  • 你能在这些值被填写之后得到SQL字符串吗?
  • 当他们解释 Query Methods: R2DBC repositories internally bind parameters to placeholders with Statement.bind(…) by index. 时,请注意 Spring Data R2DBC 文档中的第二个信息提示。请尝试将方法定义为Mono&lt;Integer&gt; updateAppt(String newNotes, long apptId, int orgId); - 注意参数顺序的变化 - 使用提供的查询并查看它是否有效。 MySQL 显然在抱怨将 'Test create Appointment...' 用作数字。

标签: mysql spring-boot spring-data-r2dbc r2dbc


【解决方案1】:

当他们解释 Query Methods 时,请注意 Spring Data R2DBC 文档中的第二个信息提示:

R2DBC 存储库内部将参数绑定到具有Statement.bind(…) 索引的占位符。

请尝试将您的方法定义为:

@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' 用作数字。

【讨论】:

    猜你喜欢
    • 2015-08-07
    • 2015-02-23
    • 2014-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-02
    相关资源
    最近更新 更多