GenerationType.AUTO delegates identifier-strategy selection to Hibernate or Spring Data JPA, which consults the configured database SQL dialect. It is equivalent to @GeneratedValue() without an explicit strategy. section 5.2.4
Generated identifier during persistence
Map an entity identifier with @Id and @GeneratedValue(strategy = GenerationType.AUTO), then persist normally:\n\nItem item = new Item();\nitem.setName("Some Item");\nitem.setAuctionEnd(Helper.tomorrow());\nem.persist(item);\n\nThe provider queues the INSERT and may assign the identifier before execution; with an INSERT-generated key, item.getId() can remain null until the INSERT occurs. section 5.2.5
Evaluate AUTO against the identifier strategy your application actually requires:
- Expect the dialect to select a sequence or identity strategy; the result can be convenient but may be less portable or efficient than an explicit choice. section 5.2.5
- Choose GenerationType.SEQUENCE for an explicit database sequence, IDENTITY for an auto-incremented column, or TABLE for a generator table. section 5.2.4
- Prefer enhanced-sequence when consistent, portable values before INSERTs and configurable optimizers matter; it uses a native sequence or emulates one with a table. section 5.2.5
