JPA Part2: Identifier Generation (PK)
There are four primary key generators. GenerationType.AUTO GenerationType.IDENTITY GenerationType.SEQUENCE GenerationType.TABLE AUTO In this case provider will use whatever the strategy support by the database. For example, MySQL 5.6 use the SEQUENCE table as follows CREATE TABLE \ ` sequence\ ` ( \ ` SEQ\_NAME\ ` varchar ( 50 ) NOT NULL , \ ` SEQ\_COUNT\ ` decimal ( 38 , 0 ) DEFAULT NULL , PRIMARY KEY ( \ ` SEQ\_NAME\ ` ) ) ENGINE = InnoDB DEFAULT CHARSET = utf8 ; As such, provider can decide the strategy. The above table is auto generated. IDENTITY Some databases support identity column referred to as auto-number where row is inserted in to the table, the identity column will get a unique identifier. Databases like MySQL 5.6 support this but not all databases. However, this is not efficient way to identity generation because identifier is not available until after the commit, therefore provider need to reread the record again after the p...