映射嵌套记录时 jOOQ 的转换器问题

发布于 2025-01-09 02:56:29 字数 1192 浏览 2 评论 0 原文

我有两个基本相同的查询,一个使用 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 调用应用转换器。我做错了什么吗?

I have two basically identical queries, one using multiset and the other using row, but they behave differently with regard to converting from SQL datatype to Java/Kotlin.

For example, here's the 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!!)
            }
        )
    }

and here's the row:

row(
    CALENDAR_ENTRIES.ID,
    CALENDAR_ENTRIES.EVENT_DATE
)
    .mapping { id: Long?, eventDate: LocalDateTime ->
        CalendarEntry(id, eventDate)
    }

For argument's sake, assuming the DB has 1 record, with eventDate being (as a String)
'2022-02-21 09:30:00'.

With the first query, I successfully get my Field<List<CalendarEntry>> instance. With the second query (row()), I get "java.time.format.DateTimeParseException: Text '2022-02-21 09:30:00' could not be parsed at index 10".

It seems that jOOQ is able to correctly apply a converter for the multiset call, but not the row call. Am I doing something wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

安静 2025-01-16 02:56:30

我假设您正在使用 PostgreSQL。

您可能在这里遇到了这个错误: https://github.com/jOOQ/jOOQ/issues/ 13117。行为上的差异可以通过以下事实来解释:从 jOOQ 3.16 开始:

  • 使用 JSONB 功能来模拟 MULTISET
  • ROW 得到
    • 嵌套在多重集中时使用 JSONB 功能进行模拟
    • 在顶层使用时使用 PostgreSQL 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 using JSONB functionality
  • ROW gets
    • emulated using JSONB functionality when nested within multiset
    • implemented natively using PostgreSQL ROW expressions when used at the top level

Bug 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文