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
IdGeneratorTypeand the deprecation has been reversed. Nevertheless, use of@GenericGeneratoris still only recommended as a migrational bridge to the recommended approach of declaring a custom annotation for each kind of generator.
-
Required Element Summary
Required ElementsModifier and TypeRequired ElementDescriptionThe type of identifier generator, a class implementingGeneratoror, more commonly,IdentifierGenerator. -
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionParameters to be passed toConfigurable.configure(Type, Properties, ServiceRegistry)when the identifier generator is instantiated.
-
Element Details
-
type
The type of identifier generator, a class implementingGeneratoror, more commonly,IdentifierGenerator. -
parameters
Parameter[] parametersParameters to be passed toConfigurable.configure(Type, Properties, ServiceRegistry)when the identifier generator is instantiated.- API Note:
- Use of
@Parameterto configure a generator is verbose and completely lacks type safety—it's much better to useIdGeneratorTypeto define a custom annotation type carrying the configuration of the specific generator class.
- Default:
{}
-