sagarswathi / h2database

Automatically exported from code.google.com/p/h2database
0 stars 1 forks source link

Postgres Serial data type should not automatically be marked as primary key #449

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
We use the 'serial' data type in our application, and based on our application 
mappings, Hibernate will generate a unique constraint because there is a 
one-to-one with a column from another table. This causes an exception with H2 
because the column is implicitly set as a primary key, so a unique constraint 
cannot be applied to it.

The relevant postgres docs that explain this are here: 
(http://www.postgresql.org/docs/8.4/static/datatype-numeric.html#DATATYPE-SERIAL
)
"In most cases you would also want to attach a UNIQUE or PRIMARY KEY constraint 
to prevent duplicate values from being inserted by accident, but this is not 
automatic."

An example create table statement:
create table my_test (my_test_id bigint generated by default as identity, 
my_test_no serial, primary key (my_test_id), unique (my_test_no));

Original issue reported on code.google.com by droberge...@gmail.com on 18 Mar 2013 at 7:10

Attachments:

GoogleCodeExporter commented 8 years ago
Sorry, I think my first paragraph is misleading. The exception in question 
occurs at CreateTable#setPrimaryKeyColumns

I think this is caused because the serial data type is automatically being set 
as a primary key

Original comment by droberge...@gmail.com on 18 Mar 2013 at 7:15

GoogleCodeExporter commented 8 years ago
Fixed in revision 4717

Original comment by noelgrandin on 2 Apr 2013 at 8:05