I am using Postgres as database and JPA 2.0 as provider.
I had been using @GeneratedValue(strategy = GenerationType.IDENTITY) which generates its own sequence for that column and also executes this query ( or similar )
ALTER TABLE "comment" ALTER COLUMN id SET DEFAULT nextval('comment_id_seq'::regclass);
Now I am using
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "GEN_COMMENT")
@SequenceGenerator(name = "GEN_COMMENT", sequenceName = "SEQ_COMMENT")
which also generates it’s own sequence but doesn’t execute that query.
My point is that when I had been using IDENTITY then database could automatically insert the column value from sequence which is helpful when there are other accesses into database except via application.
So my question is if there is any way how to force JPA to set default value of that column to sequence without redefinition of @Column(columnDefinition="...")?
Thanks a lot.
This is database specific, the Postgres has defined type
serialas generation typeIDENTITYwhich automatically creates this database structure.