jooq `myPojo` 到 `record`:记录上不可用 `store` 功能

发布于 2025-01-09 19:08:55 字数 1330 浏览 2 评论 0原文

我正在从这里的手册中学习: https:/ /www.jooq.org/doc/latest/manual/sql-execution/fetching/pojos/#NA6504

我正在尝试从 pojo 创建一条记录,并且我没有可用的 record.store() 方法或 dslContext.executeInsert(newRecord)

我的代码如下:

// this is created by me
data class Dummy(
    val name: String,
    val id: Long,
    val thisDoesNotExistInTheDatabaseAndThatsFineBecauseMappingToMyBusinessClassStillWorks: String?,
)

// table -> Business Object works ✅ 
dslContext.select()
.from(DummyTable.DUMMY_TABLE)
.fetch()
.into(Dummy::class.java)


// Business Object -> table does not work ❌ 
val newPojo = Dummy("string1", 1, null)
val newRecord: Record = dslContext.newRecord(DUMMY_TABLE, newPojo)
newRecord.store()    // this throws compilation error: Unresolved reference: store
dslContext.executeInsert(newRecord) // this throws compilation error: Type mismatch: inferred type is Record but TableRecord<*>! was expected

DUMMY_TABLE由joooq生成:open class DummyTable:TableImpl

从文档中,我的理解是 dslContext.newRecord(DUMMY_TABLE, newPojo).store() 应该可以工作。

我确信我在这里遗漏了一些明显的东西,但我不知道从哪里开始寻找。

I am learning from the manual here: https://www.jooq.org/doc/latest/manual/sql-execution/fetching/pojos/#NA6504

And i'm trying to create a Record from a pojo and i don't have available the record.store() method, or dslContext.executeInsert(newRecord).

My code looks as follows:

// this is created by me
data class Dummy(
    val name: String,
    val id: Long,
    val thisDoesNotExistInTheDatabaseAndThatsFineBecauseMappingToMyBusinessClassStillWorks: String?,
)

// table -> Business Object works ✅ 
dslContext.select()
.from(DummyTable.DUMMY_TABLE)
.fetch()
.into(Dummy::class.java)


// Business Object -> table does not work ❌ 
val newPojo = Dummy("string1", 1, null)
val newRecord: Record = dslContext.newRecord(DUMMY_TABLE, newPojo)
newRecord.store()    // this throws compilation error: Unresolved reference: store
dslContext.executeInsert(newRecord) // this throws compilation error: Type mismatch: inferred type is Record but TableRecord<*>! was expected

DUMMY_TABLE is generated by joooq: open class DummyTable: TableImpl<Record>.

From the documentation, my understanding is that dslContext.newRecord(DUMMY_TABLE, newPojo).store() should just work.

I'm sure I'm missing something obvious here, but I'm not sure where to start looking for.

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

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

发布评论

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

评论(1

野生奥特曼 2025-01-16 19:08:55

问题是您没有在变量声明中使用最合适的记录类型:

// This
val newRecord: Record = dslContext.newRecord(DUMMY_TABLE, newPojo)

// ... should be this:
val newRecord: DummyTableRecord = dslContext.newRecord(DUMMY_TABLE, newPojo)

// ... or even this:
val newRecord = dslContext.newRecord(DUMMY_TABLE, newPojo)

为了生成表记录,请在代码生成配置中激活相关标志

  • : jooq.org/doc/latest/manual/code- Generation/codegen-records/" rel="nofollow noreferrer">https://www.jooq.org/doc/latest/manual/code- Generation/codegen-records/

应该默认启用。

The problem is that you're not using the most appropriate record type in your variable declaration:

// This
val newRecord: Record = dslContext.newRecord(DUMMY_TABLE, newPojo)

// ... should be this:
val newRecord: DummyTableRecord = dslContext.newRecord(DUMMY_TABLE, newPojo)

// ... or even this:
val newRecord = dslContext.newRecord(DUMMY_TABLE, newPojo)

In order to get the table records generated, please activate the relevant flag in your code generation configuration:

It should be enabled by default.

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