Solving the problem at hand
You don't have to include the ID column. Why not just write this instead?
context
// No ID column here
.insertInto(MY_TABLE, MY_TABLE.STATUS, MY_TABLE.NAME)
// Use a Record2<?, ?> type here
.valuesOfRecords(records)
.returningResult(MY_TABLE.ID)
.fetchInto(Long.class);
If your records are the generated MyTableRecord which you configured to extend Record3<?, ?, ?>, you'll just have to map the desired content to a Record2<?, ?>, or even to a Row2<?, ?>:
context
.insertInto(MY_TABLE, MY_TABLE.STATUS, MY_TABLE.NAME)
.valuesOfRows(records
.stream()
// An example mapping.
.map(r -> row(r.getStatus(), r.getName()))
.toList()
)
.returningResult(MY_TABLE.ID)
.fetchInto(Long.class);
The jOOQ 3.15 org.jooq.Rows utility has a few mapping functions that help with such cases. You could even write:
context
.insertInto(MY_TABLE, MY_TABLE.STATUS, MY_TABLE.NAME)
.valuesOfRows(records
.stream()
.collect(Rows.toRowList(r -> r.getStatus(), r -> r.getName()))
)
.returningResult(MY_TABLE.ID)
.fetchInto(Long.class);
Using 3.16 readonly columns
Starting from jOOQ 3.16, there is support for readonly columns:
If jOOQ knows your ID column is readonly (and it is, if it's an identity column), then it will ignore it from such statement if you configure it accordingly.