INSERT..RETURNING在JOOQ中不起作用 [英] INSERT..RETURNING is not working in JOOQ

查看:143
本文介绍了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中的已知限制:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆