INSERT..RETURNING is not working in JOOQ(INSERT..RETURNING 在 JOOQ 中不起作用)
问题描述
我有一个 MariaDB 数据库,我正在尝试在我的表 users 中插入一行.它有一个生成的 id ,我想在插入后得到它.我见过 这个 但它对我不起作用:
I have a MariaDB database and I'm trying to insert a row in my table users. It has a generated id and I want to get it after insert. I have seen this but it's not working for me:
public Integer addNewUser(String name) {
Record record = context.insertInto(table("users"), field("name"))
.values(name)
.returning(field("id"))
.fetchOne();
return record.into(Integer.class);
}
插入了新行,但 record 始终为 null.我没有使用 JOOQ 代码生成.
New row is inserted but record is always null. I'm not using JOOQ code generation.
推荐答案
这是 jOOQ 3.9 中的一个已知限制:https://github.com/jOOQ/jOOQ/issues/2943
This is a known limitation in jOOQ 3.9: https://github.com/jOOQ/jOOQ/issues/2943
在使用纯 SQL 时,您目前不能在 jOOQ 中使用 RETURNING 子句,因为 jOOQ 需要知道标识列名称才能绑定到 JDBC(在大多数数据库中).不幸的是,将 ID 列传递给 RETURNING 子句是不够的,因为不能保证这是标识列.您还可以将几列传递给 RETURNING 子句,以防 jOOQ 不知道哪一列是标识列.
You currently cannot use the RETURNING clause in jOOQ when using plain SQL, because jOOQ needs to know the identity column name to bind to JDBC (in most databases). Unfortunately, passing the ID column to the RETURNING clause isn't sufficient, because there's no guarantee that this is the identity column. You might also pass several columns to the RETURNING clause, in case of which jOOQ wouldn't know which one would be the identity column.
这篇关于INSERT..RETURNING 在 JOOQ 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:INSERT..RETURNING 在 JOOQ 中不起作用
基础教程推荐
- 在java中使用xpath和selenium解析HTML表格数据 2022-01-01
- 如何在相机中应用自定义滤镜 [Surfaceview 预览]. 2022-01-01
- Maven:无效的目标版本:10 2022-01-01
- doFilter()是在servlet的工作完成之前还是之后执行的? 2022-01-01
- Java ECDSAwithSHA256 签名长度不一致 2022-01-01
- 在springboot中如何给mybatis加拦截器 2023-04-29
- 将 double 转换为 Int,向下舍入 2022-01-01
- 控制台应用程序中的 Java 键盘输入解析 2022-01-01
- 将 Windows 证书导入 Java 2022-01-01
- JPA惰性列表上的流 2022-01-01
