Given:
CREATE TABLE foo (id BIGINT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id));
I’d like to invoke: INSERT INTO foo VALUES() and get back the generated key. I tried following the advice found at jOOQ insert query with returning generated keys but when I invoke:
RoomsRecord record = db.insertInto(foo, Collections<Field<?>>emptyList()).returning(foo.ID).fetchOne();
JOOQ returns null instead of the generated key. Is this a bug?
This seems to be a bug in FieldMapsForInsert.isExecutable(). It flags the above query as non-executable but it is legal under MySQL. I filed https://github.com/jOOQ/jOOQ/issues/20
You can insert
NULLas a workaround. Furthermore, you must configure JOOQ to generate table “relations”, otherwisereturning()won’t see the existence of primary keys and return null.