Hibernate Auto Generated Primary Keys : Auto-increment is a feature in databases that automatically generates a unique value for a column each time a new row is added to a table. This is commonly used for primary key columns to ensure each row has a unique identifier.
ID Generation Strategy: In Hibernate, an ID generation strategy determines how primary key values for entities are generated. Auto-increment is one of the strategies where the database automatically assigns a unique value.
import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.Table; @Table(name="book") @Entity public class Book{ @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id", updatable = false, nullable = false) private Long id; }
Java Hibernate Magic: Create MySQL Tables with Ease and Efficiency