Annotation Type IdGeneratorType

    public @interface IdGeneratorType
    Meta-annotation used to mark another annotation as providing configuration for a custom identifier generator. This is the best way to work with customized identifier generation in Hibernate.

    For example, if we have a custom identifier generator:

     public class CustomSequenceGenerator implements BeforeExecutionGenerator {
         public CustomSequenceGenerator(CustomSequence config, Member annotatedMember,
                                        CustomIdGeneratorCreationContext context) {

    Then we may also define an annotation which associates this generator with an entity and supplies configuration parameters:

     @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-defined GeneratedValue here, since that API is designed around the use of stringly-typed names. The @CustomSequence annotation itself implies that id is a generated value.

    An id generator annotation may have members, which are used to configure the id generator, if either:

    For a more complete example, see the annotation UuidGenerator and the corresponding generator class UuidGenerator.

    A @IdGeneratorType annotation must have retention policy RetentionPolicy.RUNTIME.

    See Also:
    Generator, AnnotationBasedGenerator
    • Required Element Summary

      Required Elements 
      Modifier and Type Required Element Description
      Class<? extends Generator> value
      A class which implements Generator.