GenerationType standardizes JPA strategies for generating entity identifier values. Combine it with @Id and @GeneratedValue when the database or persistence provider should assign a primary key; omit @GeneratedValue when the application assigns identifiers manually. section 5.2.4
Choose a strategy according to database capabilities and control requirements:
- AUTO lets Hibernate select a suitable strategy from the configured database SQL dialect and is equivalent to @GeneratedValue() without settings. section 5.2.4
- SEQUENCE calls a database sequence before each INSERT; the default expected name is HIBERNATE_SEQUENCE. section 5.2.4
- IDENTITY expects a database auto-increment column that generates the numeric key during INSERT. section 5.2.4
- TABLE reads and updates an auxiliary table holding the next numeric value, with one row per entity class. section 5.2.4
Persisting an entity with a generated identifier
Annotate an entity identifier with @GeneratedValue(strategy = GenerationType.SEQUENCE), then persist a new Item. Hibernate obtains the generated value and assigns it as part of persistence. section 5.2.4
