Annotation Interface IdGeneratorType
For example, if we have a custom identifier generator:
public class CustomSequenceGenerator implements BeforeExecutionGenerator { public CustomSequenceGenerator(CustomSequence config, Member annotatedMember, GeneratorCreationContext context) { ... } ... }Then we may also define an annotation which associates this generator with an entity and supplies configuration parameters:
@IdGeneratorType(CustomSequenceGenerator.class) @Retention(RUNTIME) @Target({METHOD,FIELD}) public @interface CustomSequence { String name(); int startWith() default 1; int incrementBy() default 50; }and we may use it as follows:
@Id @CustomSequence(name = "mysequence", startWith = 0) private Integer id;
We did not use the JPA-definedGeneratedValue here, since that API is designed around the use of stringly-typed names. The@CustomSequence annotation itself implies thatid is a generated value.
An id generator annotation may have members, which are used to configure the id generator, if either:
- the id generator implements
AnnotationBasedGenerator, or - the id generator class has a constructor with the same signature as
AnnotationBasedGenerator.initialize(A, java.lang.reflect.Member, org.hibernate.generator.GeneratorCreationContext).
For a more complete example, see the annotationUuidGenerator and the corresponding generator classUuidGenerator.
A@IdGeneratorType annotation must have retention policyRetentionPolicy.RUNTIME.
If aGenerator may be used to generate values of non-identifier fields, its generator annotation should also be meta-annotated@ValueGenerationType.
- Since:
- 6.0
- See Also:
Required Element Summary
Required Elements
Element Details
value
A class which implementsGenerator.