How can we auto-generate primary key in Hibernate?

We can use the primary key generation strategy of type GenerationType.AUTO to auto-generate primary key while persisting an object in Hibernate.

private int id;
We can leave it null/0 while persisting and Hibernate automatically generates a primary key for us.

Sometimes, AUTO strategy refers to a SEQUENCE instead of an IDENTITY .

Leave a Reply

Your email address will not be published. Required fields are marked *