If I have @GeneratedValue(strategy = GenerationType.IDENTITY)
above my id in an Hibernate entity, should I use only SERIAL
or INTEGER
with manually set up sequence for it? Is it possible to use default INTEGER
or BIGINT
? If it's not possible, then why? I thought strategy = GenerationType.IDENTITY
means that Hibernate will care about generating id in case of its nullability, not database.
I'm using PostgreSQL.
If I have @GeneratedValue(strategy = GenerationType.IDENTITY)
above my id in an Hibernate entity, should I use only SERIAL
or INTEGER
with manually set up sequence for it? Is it possible to use default INTEGER
or BIGINT
? If it's not possible, then why? I thought strategy = GenerationType.IDENTITY
means that Hibernate will care about generating id in case of its nullability, not database.
I'm using PostgreSQL.
You can use either of them. However, using SERIAL
is always a better option for columns like ID because it can automatically increment the IDs which is really helpful when the ID column is left blank or null or during database insertions. INTEGER OR BIGINT
(without the attached sequence) cannot handle/support this.