INSERT..RETURNING在JOOQ中不起作用 [英] INSERT..RETURNING is not working in 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.
推荐答案
This is a known limitation in jOOQ 3.9: https://github.com/jOOQ/jOOQ/issues/2943
在使用纯SQL时,当前无法在jOOQ中使用RETURNING
子句,因为jOOQ需要知道标识列名称以绑定到JDBC(在大多数数据库中).不幸的是,仅将ID
列传递给RETURNING
子句是不够的,因为无法保证这是Identity列.您还可以将几列传递给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中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!