JOOQ r2dbc 获取数据:无法解码具有 OID 51968 的 java.lang.String 类型的值
Posted
技术标签:
【中文标题】JOOQ r2dbc 获取数据:无法解码具有 OID 51968 的 java.lang.String 类型的值【英文标题】:JOOQ r2dbc fetching data: Cannot decode value of type java.lang.String with OID 51968 【发布时间】:2021-11-04 09:55:56 【问题描述】:我在我的 Spring 应用程序中使用 jooq 3.15 和 r2dbc,但从数据库中获取数据时遇到了问题。
我使用 6.0.1 版本的 nu.studer.jooq 在我的 gradle 文件中设置 jooq:
jooq
version.set("3.15.1")
edition.set(nu.studer.gradle.jooq.JooqEdition.OSS)
configurations
create("main")
generateSchemaSourceOnCompilation.set(false)
jooqConfiguration.apply
logging = org.jooq.meta.jaxb.Logging.WARN
jdbc.apply
driver = "org.postgresql.Driver"
url = "jdbc:postgresql://localhost:15432/core_ticker"
user = ""
password = ""
generator.apply
database.apply
name = "org.jooq.meta.postgres.PostgresDatabase"
inputSchema = "public"
includes = ".*"
excludes =
"flyway_schema_history"
generate.apply
isRelations = true
isDeprecated = false
isRecords = true
isImmutablePojos = true
isFluentSetters = true
target.apply
packageName = "rc.core.ticker.domain.db"
directory = "src/main/java"
我有下一个获取汇率的代码:
fun getRate(
fromCurrency: Currency,
toCurrency: Currency,
source: CurrencySource,
date: LocalDate?
) = Mono.from(
context.selectFrom(Tables.CURRENCY_RATE)
.where(Tables.CURRENCY_RATE.CURRENCY_FROM.eq(fromCurrency.value))
.and(Tables.CURRENCY_RATE.CURRENCY_TO.eq(toCurrency.value))
.limit(1)
).mapNotNull(CurrencyRate.Mapper::map).awaitSingle()
但由于Mono.from
内的代码异常,下一个堆栈跟踪,我不会获取数据:
java.lang.IllegalArgumentException: Cannot decode value of type java.lang.String with OID 51968
at io.r2dbc.postgresql.codec.DefaultCodecs.decode(DefaultCodecs.java:158) ~[r2dbc-postgresql-0.8.8.RELEASE.jar:0.8.8.RELEASE]
at io.r2dbc.postgresql.PostgresqlRow.decode(PostgresqlRow.java:90) ~[r2dbc-postgresql-0.8.8.RELEASE.jar:0.8.8.RELEASE]
at io.r2dbc.postgresql.PostgresqlRow.get(PostgresqlRow.java:67) ~[r2dbc-postgresql-0.8.8.RELEASE.jar:0.8.8.RELEASE]
at org.jooq.impl.R2DBC$R2DBCResultSet$DefaultRow.get(R2DBC.java:1110) ~[jooq-3.15.1.jar:na]
at org.jooq.impl.R2DBC$R2DBCResultSet.nullable(R2DBC.java:989) ~[jooq-3.15.1.jar:na]
at org.jooq.impl.R2DBC$R2DBCResultSet.nullable(R2DBC.java:985) ~[jooq-3.15.1.jar:na]
at org.jooq.impl.R2DBC$R2DBCResultSet.getString(R2DBC.java:1050) ~[jooq-3.15.1.jar:na]
at org.jooq.impl.DefaultBinding$DefaultEnumTypeBinding.get0(DefaultBinding.java:2560) ~[jooq-3.15.1.jar:na]
at org.jooq.impl.DefaultBinding$DefaultEnumTypeBinding.get0(DefaultBinding.java:2527) ~[jooq-3.15.1.jar:na]
at org.jooq.impl.DefaultBinding$AbstractBinding.get(DefaultBinding.java:942) ~[jooq-3.15.1.jar:na]
at org.jooq.impl.R2DBC$ResultSubscriber.lambda$onNext$0(R2DBC.java:327) ~[jooq-3.15.1.jar:na]
at org.jooq.impl.RecordDelegate.operate(RecordDelegate.java:143) ~[jooq-3.15.1.jar:na]
at org.jooq.impl.R2DBC$ResultSubscriber.lambda$onNext$1(R2DBC.java:313) ~[jooq-3.15.1.jar:na]
at io.r2dbc.postgresql.PostgresqlResult.lambda$map$1(PostgresqlResult.java:111) ~[r2dbc-postgresql-0.8.8.RELEASE.jar:0.8.8.RELEASE]
at reactor.core.publisher.FluxHandle$HandleSubscriber.onNext(FluxHandle.java:103) ~[reactor-core-3.4.9.jar:3.4.9]
at reactor.core.publisher.MonoFlatMapMany$FlatMapManyInner.onNext(MonoFlatMapMany.java:250) ~[reactor-core-3.4.9.jar:3.4.9]
at reactor.core.publisher.FluxHandleFuseable$HandleFuseableSubscriber.onNext(FluxHandleFuseable.java:184) ~[reactor-core-3.4.9.jar:3.4.9]
at reactor.core.publisher.FluxFilterFuseable$FilterFuseableConditionalSubscriber.onNext(FluxFilterFuseable.java:337) ~[reactor-core-3.4.9.jar:3.4.9]
at reactor.core.publisher.FluxContextWrite$ContextWriteSubscriber.onNext(FluxContextWrite.java:107) ~[reactor-core-3.4.9.jar:3.4.9]
at reactor.core.publisher.FluxPeekFuseable$PeekConditionalSubscriber.onNext(FluxPeekFuseable.java:854) ~[reactor-core-3.4.9.jar:3.4.9]
at reactor.core.publisher.FluxPeekFuseable$PeekConditionalSubscriber.onNext(FluxPeekFuseable.java:854) ~[reactor-core-3.4.9.jar:3.4.9]
at io.r2dbc.postgresql.util.FluxDiscardOnCancel$FluxDiscardOnCancelSubscriber.onNext(FluxDiscardOnCancel.java:86) ~[r2dbc-postgresql-0.8.8.RELEASE.jar:0.8.8.RELEASE]
at reactor.core.publisher.FluxCreate$BufferAsyncSink.drain(FluxCreate.java:793) ~[reactor-core-3.4.9.jar:3.4.9]
at reactor.core.publisher.FluxCreate$BufferAsyncSink.next(FluxCreate.java:718) ~[reactor-core-3.4.9.jar:3.4.9]
at reactor.core.publisher.FluxCreate$SerializedFluxSink.next(FluxCreate.java:154) ~[reactor-core-3.4.9.jar:3.4.9]
at io.r2dbc.postgresql.client.ReactorNettyClient$Conversation.emit(ReactorNettyClient.java:735) ~[r2dbc-postgresql-0.8.8.RELEASE.jar:0.8.8.RELEASE]
at io.r2dbc.postgresql.client.ReactorNettyClient$BackendMessageSubscriber.emit(ReactorNettyClient.java:986) ~[r2dbc-postgresql-0.8.8.RELEASE.jar:0.8.8.RELEASE]
at io.r2dbc.postgresql.client.ReactorNettyClient$BackendMessageSubscriber.onNext(ReactorNettyClient.java:860) ~[r2dbc-postgresql-0.8.8.RELEASE.jar:0.8.8.RELEASE]
at io.r2dbc.postgresql.client.ReactorNettyClient$BackendMessageSubscriber.onNext(ReactorNettyClient.java:767) ~[r2dbc-postgresql-0.8.8.RELEASE.jar:0.8.8.RELEASE]
at reactor.core.publisher.FluxHandle$HandleSubscriber.onNext(FluxHandle.java:119) ~[reactor-core-3.4.9.jar:3.4.9]
at reactor.core.publisher.FluxPeekFuseable$PeekConditionalSubscriber.onNext(FluxPeekFuseable.java:854) ~[reactor-core-3.4.9.jar:3.4.9]
at reactor.core.publisher.FluxMap$MapConditionalSubscriber.onNext(FluxMap.java:220) ~[reactor-core-3.4.9.jar:3.4.9]
at reactor.core.publisher.FluxMap$MapConditionalSubscriber.onNext(FluxMap.java:220) ~[reactor-core-3.4.9.jar:3.4.9]
at reactor.netty.channel.FluxReceive.drainReceiver(FluxReceive.java:279) ~[reactor-netty-core-1.0.10.jar:1.0.10]
at reactor.netty.channel.FluxReceive.onInboundNext(FluxReceive.java:388) ~[reactor-netty-core-1.0.10.jar:1.0.10]
at reactor.netty.channel.ChannelOperations.onInboundNext(ChannelOperations.java:404) ~[reactor-netty-core-1.0.10.jar:1.0.10]
at reactor.netty.channel.ChannelOperationsHandler.channelRead(ChannelOperationsHandler.java:93) ~[reactor-netty-core-1.0.10.jar:1.0.10]
我认为我的问题的主要原因是隐藏在下一个跟踪块中:
at org.jooq.impl.R2DBC$R2DBCResultSet$DefaultRow.get(R2DBC.java:1110) ~[jooq-3.15.1.jar:na]
at org.jooq.impl.R2DBC$R2DBCResultSet.nullable(R2DBC.java:989) ~[jooq-3.15.1.jar:na]
at org.jooq.impl.R2DBC$R2DBCResultSet.nullable(R2DBC.java:985) ~[jooq-3.15.1.jar:na]
at org.jooq.impl.R2DBC$R2DBCResultSet.getString(R2DBC.java:1050) ~[jooq-3.15.1.jar:na]
at org.jooq.impl.DefaultBinding$DefaultEnumTypeBinding.get0(DefaultBinding.java:2560) ~[jooq-3.15.1.jar:na]
我的表中有一个枚举列,但它不能为空。
【问题讨论】:
【参考方案1】:r2dbc-postgresql 驱动程序存在一个已知限制,如果您没有事先手动注册枚举类型,它目前无法反序列化枚举类型: https://github.com/pgjdbc/r2dbc-postgresql/issues/429
以下是有关如何执行此操作的一些说明:https://github.com/pgjdbc/r2dbc-postgresql#postgres-enum-types
【讨论】:
非常感谢!希望相信它会尽快修复。 @NikitaNamestnikov:成为你希望在世界上看到的改变!以上是关于JOOQ r2dbc 获取数据:无法解码具有 OID 51968 的 java.lang.String 类型的值的主要内容,如果未能解决你的问题,请参考以下文章