映射嵌套记录时 jOOQ 的转换器问题
我有两个基本相同的查询,一个使用 multiset
,另一个使用 row
,但它们在从 SQL 数据类型转换为 Java/Kotlin 方面的行为不同。
例如,这里是multiset
:
multiset(
select(
CALENDAR_ENTRIES.ID,
CALENDAR_ENTRIES.EVENT_DATE
)
.from(CALENDAR_ENTRIES)
.where(cond)
).`as`("calendar_entry")
.convertFrom { r: Result<Record2<Long, LocalDateTime>> ->
r.map(
Records.mapping { id: Long?, eventDate: LocalDateTime? ->
CalendarEntry(id, eventDate!!)
}
)
}
这里是row
:
row(
CALENDAR_ENTRIES.ID,
CALENDAR_ENTRIES.EVENT_DATE
)
.mapping { id: Long?, eventDate: LocalDateTime ->
CalendarEntry(id, eventDate)
}
为了论证起见,假设数据库有1条记录,eventDate
是(作为细绳)
'2022-02-21 09:30:00'。
通过第一个查询,我成功获取了 Field
实例。在第二个查询 (>
row()
) 中,我得到“java.time.format.DateTimeParseException: Text '2022-02-21 09:30:00' can not be parsed at index 10”。
看来 jOOQ 能够正确地为 multiset
调用应用转换器,但不能为 row
调用应用转换器。我做错了什么吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您正在使用 PostgreSQL。
您可能在这里遇到了这个错误: https://github.com/jOOQ/jOOQ/issues/ 13117。行为上的差异可以通过以下事实来解释:从 jOOQ 3.16 开始:
JSONB
功能来模拟MULTISET
ROW
得到JSONB
功能进行模拟ROW
表达式本地实现错误 https://github.com/jOOQ/jOOQ/issues/13117 似乎也影响顶层
ROW
类型,而不仅仅是 UDT。它最近已被修复,并且可能会向后移植到 3.16 和 3.15。I'm assuming you're using PostgreSQL.
You probably ran into this bug here: https://github.com/jOOQ/jOOQ/issues/13117. The difference in behaviour is explained by the fact that as of jOOQ 3.16:
MULTISET
gets emulated usingJSONB
functionalityROW
getsJSONB
functionality when nested within multisetROW
expressions when used at the top levelBug https://github.com/jOOQ/jOOQ/issues/13117 seems to affect also top level
ROW
types, not just UDTs. It has been fixed recently, and might be backported to 3.16 and 3.15.