Interface AnnotationBasedGenerator<A extends Annotation>

Type Parameters:
A - The generator annotation type supported by an implementation
All Superinterfaces:
Generator, Serializable
All Known Implementing Classes:
NativeGenerator

public interface AnnotationBasedGenerator<A extends Annotation> extends Generator
A Generator which receives parameters from a custom generator annotation or id generator annotation.

Implementing this interface is the same as providing a constructor with the same signature as the initialize(A, Member, GeneratorCreationContext) method. But implementing this interface is slightly more typesafe.

For example, implementing AnnotationBasedGenerator<AnnotationType> is the same as providing a constructor with this signature:

public GeneratorClass(AnnotationType config,
                     GeneratorCreationContext creationContext)

where GeneratorClass is the class that implements Generator, and AnnotationType is the generator annotation type used to configure the generator. That is, it is an annotation type annotated @ValueGenerationType or @IdGeneratorType.

@IdGeneratorType(GeneratorClass.class)
public @interface AnnotationType { ... }

Every instance of this interface must also implement either BeforeExecutionGenerator or OnExecutionGenerator.

Since:
6.2
See Also:
  • Method Details

    • initialize

      @Deprecated(since="7.3", forRemoval=true) default void initialize(A annotation, Member member, GeneratorCreationContext context)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Initializes this generation strategy for the given annotation instance.
      Parameters:
      annotation - an instance of the strategy's annotation type. Typically, implementations will retrieve the annotation's attribute values and store them in fields.
      member - the Java member annotated with the generator annotation.
      context - a GeneratorCreationContext
      Throws:
      HibernateException - in case an error occurred during initialization, for example, if an implementation can't create a value for the given property type.
    • initialize

      default void initialize(A annotation, GeneratorCreationContext context)
      Initializes this generation strategy for the given annotation instance.
      Parameters:
      annotation - an instance of the strategy's annotation type. Typically, implementations will retrieve the annotation's attribute values and store them in fields.
      context - a GeneratorCreationContext
      Throws:
      HibernateException - in case an error occurred during initialization, for example, if an implementation can't create a value for the given property type.
      Since:
      7.3