Package org.hibernate.annotations
Annotation Type GenericGenerator
@Target({PACKAGE,TYPE,METHOD,FIELD})@Retention(RUNTIME)@Repeatable(GenericGenerators.class)@Deprecated(since="6.5")public @interfaceGenericGenerator
Deprecated.Use the new approach based onIdGeneratorType.Defines a named identifier generator, usually an instance of the interfaceIdentifierGenerator. This allows the use of custom identifier generation strategies beyond those provided by the four basic JPA-definedgeneration types.A named generator may be associated with an entity class by:
- defining a named generator using this annotation, specifying an implementation of
IdentifierGeneratorusingtype(), then - annotating the identifier property of the entity with the JPA-defined
@GeneratedValueannotation, and - using
generatorto specify thename()of the generator defined using this annotation.
If neither
type()notstrategy()is specified, Hibernate asksthe dialect to decide an appropriate strategy. This is equivalent to usingAUTOin JPA.For example, if we define a generator using:
@GenericGenerator(name = "custom-generator", type = org.hibernate.eg.CustomStringGenerator.class) }
Then we may make use of it by annotating an identifier field as follows:
@Id @GeneratedValue(generator = "custom-generator") private String id;
The disadvantage of this approach is the use of stringly-typed names. An alternative, completely typesafe, way to declare a generator and associate it with an entity is provided by the
@IdGeneratorTypemeta-annotation.- See Also:
GeneratedValue
- defining a named generator using this annotation, specifying an implementation of
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description Parameter[]parametersDeprecated.Parameters to be passed toIdentifierGenerator.configure(org.hibernate.type.Type, java.util.Properties, org.hibernate.service.ServiceRegistry)when the identifier generator is instantiated.StringstrategyDeprecated.usetype()for typesafetyClass<? extendsGenerator>typeDeprecated.The type of identifier generator, a class implementingGeneratoror, more commonly,IdentifierGenerator.
Element Detail
name
String name
Deprecated.The name of the identifier generator. This is the name that may be specified by thegeneratormember of the@GeneratedValueannotation.- See Also:
GeneratedValue.generator()
type
Class<? extendsGenerator> type
Deprecated.The type of identifier generator, a class implementingGeneratoror, more commonly,IdentifierGenerator.- Since:
- 6.2
- Default:
- org.hibernate.generator.Generator.class
strategy
@Deprecated(since="6.2")String strategy
Deprecated.usetype()for typesafetyThe type of identifier generator, the name of either:- a built-in Hibernate id generator, or
- a custom class implementing
Generator, or, more commonly,IdentifierGenerator.
- Default:
- "native"
parameters
Parameter[] parameters
Deprecated.Parameters to be passed toIdentifierGenerator.configure(org.hibernate.type.Type, java.util.Properties, org.hibernate.service.ServiceRegistry)when the identifier generator is instantiated.- Default:
- {}