Suppressing a primary key return on updatable records
In the previous section, you saw that jOOQ automatically fetches and sets the generated primary key for updatable records. Suppressing this action can be done via the withReturnIdentityOnUpdatableRecord()
flag setting. In some dialects, a database round trip (the lastID()
style) can be prevented, so this is mostly a performance feature. By default, this flag is true
, but if we explicitly set it to false
, then jOOQ will no longer attempt to fetch the generated primary key:
DSLContext derivedCtx = ctx.configuration().derive( new Settings().withReturnIdentityOnUpdatableRecord(false)) .dsl(); SaleRecord sr = derivedCtx.newRecord(SALE); sr.setFiscalYear(2021); ... sr.insert();
This time, calling sr.getSaleId()
returns null
.