jooq `myPojo` 到 `record`:记录上不可用 `store` 功能
我正在从这里的手册中学习: 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是您没有在变量声明中使用最合适的记录类型:
为了生成表记录,请在代码生成配置中激活相关标志
应该默认启用。
The problem is that you're not using the most appropriate record type in your variable declaration:
In order to get the table records generated, please activate the relevant flag in your code generation configuration:
It should be enabled by default.