Annotation Interface GenericGenerator


@Target({METHOD,FIELD,TYPE,PACKAGE}) @Retention(RUNTIME) @Incubating public @interface GenericGenerator
Specifies a generator used for generating entity identifiers, allowing the use of custom identifier generation strategies going beyond those provided by the four standard JPA-defined generation types.

When @GenericGenerator directly annotates a field, the @GeneratedValue annotation is not required:

@Id
@GenericGenerator(type = CustomUuidGenerator.class)
private String uuid;

On the other hand, when @GenericGenerator annotates a class or package, @GeneratedValue must be applied to the generated id field:

@Entity
@GenericGenerator(type = CustomUuidGenerator.class)
class Record {
    @Id
    @GeneratedValue
    private String uuid;
    ...
}
See Also:
API Note:
This annotation has been substantially reworked after a period of being marked as deprecated, and its semantics have changed significantly. Previously, it registered a named generator using legacy infrastructure. It is now redefined as an IdGeneratorType and the deprecation has been reversed. Nevertheless, use of @GenericGenerator is still only recommended as a migrational bridge to the recommended approach of declaring a custom annotation for each kind of generator.