Gokul
Gokul

Reputation: 277

autogenerated primary keys in postgres with jooq

I am using jooq generated dao's to do a create operation on a table. The table has a primary key 'id' with type bigserial and the default constraints of not null

CREATE TABLE public.book (
  id bigserial NOT NULL,
  author varchar(64)
  CONSTRAINT book_primary PRIMARY KEY (id)
)

to create a record with jooq i say

Book b = new Book();
b.setAuthor("Eric");
BookDao bd = new BookDao(jooqConfiguration);
bd.insert(b);

This throws a constrain violation exception that id is null.If i set an id such as

Book b = new Book();
b.setId(25);
b.setAuthor("Eric");
BookDao bd = new BookDao(jooqConfiguration);
bd.insert(b);

I do not get the exception but postgres does not generate a value automatically.

The postgres documentation at http://www.postgresql.org/docs/current/static/datatype-numeric.html#DATATYPE-SERIAL says the "Omit the SERIAL column in INSERT, or specify DEFAULT keyword"

How do i configure the jooq generated dao to either omit this column or use a value of DEFAULT

Edit - I am using jooq version 3.3.2 and postgres 8.4. ( The final target is aws redshift. So prototyping on postgres 8.4).

Upvotes: 2

Views: 2510

Answers (1)

Gokul
Gokul

Reputation: 277

This issue of generated dao's not properly handling handling default values is already present in jooq's list of github issues as https://github.com/jOOQ/jOOQ/issues/2700.

It is fixed in 3.4.0. Migrating to 3.4.0 fixed the issue for me.

answering the question so that other can find it if required.

Upvotes: 2

Related Questions