@ Generatedvalue: The primary key generation policy, which is specified through the Strategy attribute.
The primary key generation policy is specified by generationtype. Generationtype is an enumeration that defines the type of primary key generation policy.
1. Auto automatically selects a primary key generation policy most suitable for the underlying database. For example, MySQL automatically corresponds to auto increment. This is the default option. If you only write @ generatedvalue, it is equivalent to @ generatedvalue (Strategy = generationtype. Auto ).
2. The self-increment field in the identity table. Oracle does not support this method.
3. Sequence generates primary keys through sequences. MySQL does not support this method.
4. Tables generate primary keys through tables. The framework uses the table simulation sequence to generate primary keys. Using this policy makes the application easier to port databases. Different JPA implementers generate different table names. For example, openjpa generates openjpa_sequence_table table, Hibernate generates a hibernate_sequences table, and toplink generates a sequence table. These tables have two fields, seq_name and seq_count.
In our applications, @ generatedvalue (Strategy = generationtype. Auto) is generally used to automatically select a primary key generation policy to adapt to different database migrations.
If you use hibernate to implement JPA, you can use hibernate to extend the primary key generation policy through hibernate's @ genericgenerator.
@ Genericgenerator (name = "system-UUID", strategy = "UUID") declares a general policy generator. The name is "system-UUID", and the policy strategy is "UUID ".
@ Generatedvalue (generator = "system-UUID") use the generator attribute to specify the Policy Generator to be used.
This is a method I use in projects. It generates a 32-bit string and is a unique value. The most common, applicable to all databases.