INSERT..RETURNING is not working in JOOQ

天大地大妈咪最大 提交于 2019-12-23 12:13:30

问题


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);
}

New row is inserted but record is always null. I'm not using JOOQ code generation.


回答1:


This is a known limitation in jOOQ 3.9: https://github.com/jOOQ/jOOQ/issues/2943

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.



来源:https://stackoverflow.com/questions/41264116/insert-returning-is-not-working-in-jooq

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!