Sander Plas
unread,May 3, 2011, 9:52:53 AM5/3/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to jOOQ User Group
My PostgreSQL table definition:
---------------------------------------------------------------------------------------------------------
Table "public.product_group"
Column | Type |
Modifiers
--------+--------------------
+------------------------------------------------------------
id | integer | not null default
nextval('seq_product_group_id'::regclass)
name | character varying | not null
ord | integer |
type | product_group_type |
Indexes:
"product_group_pkey" PRIMARY KEY, btree (id)
Referenced by:
TABLE "product" CONSTRAINT "product_product_group_id_fkey" FOREIGN
KEY (product_group_id) REFERENCES product_group(id)
---------------------------------------------------------------------------------------------------------
java/jOOQ code:
---------------------------------------------------------------------------------------------------------
ProductGroupRecord pgr =
query().newRecord(ProductGroup.PRODUCT_GROUP);
pgr.setName("...vul in...");
pgr.store();
---------------------------------------------------------------------------------------------------------
PostgreSQL log:
---------------------------------------------------------------------------------------------------------
2011-05-03 15:27:15 CEST LOG: execute <unnamed>: insert into
public.product_group (id, name, ord, type) values (null, $1, null,
null)
2011-05-03 15:27:15 CEST DETAIL: parameters: $1 = '...vul in...'
2011-05-03 15:27:15 CEST ERROR: null value in column "id" violates
not-null constraint
2011-05-03 15:27:15 CEST STATEMENT: insert into public.product_group
(id, name, ord, type) values (null, $1, null, null)
---------------------------------------------------------------------------------------------------------
As you can see, i don't explicitly call pgr.setId(null) in my code,
but jOOQ does explicitly set id to null in the insert query. This
means that PostgreSQL won't use the 'default' value (sequence) that is
set on the 'id' column.
Is this intended behaviour?
Would it be possible (and a good idea?) to leave out columns that
haven't been defined explicitly from the generated SQL to allow the
database to fill in default values?