Reputation: 3634
JOOQ offers the very nice ability to do the following:
TableRecord tableRecord = dsl.newRecord(TABLE);
tableRecord.setSomeParam(...);
tableRecord.insert();
At this point the record should be inserted in the table.
We can do something like:
tableRecord.getSomeParam(); // will return value above
However, this:
tableRecord.getId(); // NULL
Always returns null
. Is this by design? Do we have to use returning(TABLE.ID)
to get the autogenerated ID value instead of the Record
? Is this behaviour different if the query is executed in a transactional context?
Edit:
I am using PostgreSQL 9.4.10, and my table definition is similar to the following:
CREATE TABLE item
(
id bigserial NOT NULL,
name character varying(245),
some_uuid uuid NOT NULL DEFAULT uuid_generate_v4(),
CONSTRAINT item_pkey PRIMARY KEY (id),
CONSTRAINT item_item_uuid_key UNIQUE (item_uuid)
)
Additional information:
3.8.6
Upvotes: 1
Views: 3654
Reputation: 1738
Use store()
method (https://www.jooq.org/javadoc/3.2.0/org/jooq/UpdatableRecord.html#store())
Autogenerated ID will be refreshed after storing record.
You could also call record.refresh()
after insert
, then your record will contain refreshed values.
Upvotes: 2