Interface AnnotationBasedUserType<A extends Annotation, J>

Type Parameters:
A - The user type annotation type supported by an implementation
J - The java type
All Superinterfaces:
UserType<J>

@Incubating public interface AnnotationBasedUserType<A extends Annotation, J> extends UserType<J>
A UserType which receives parameters from a custom annotation.

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

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

public CustomTypeClass(AnnotationType config,
                       UserTypeCreationContext creationContext)

where CustomTypeClass is the class that implements UserType, and AnnotationType is the custom annotation type used to configure the custom type. That is, it is an annotation type annotated @Type.

@Type(CustomTypeClass.class)
public @interface AnnotationType { ... }
Since:
7.3
  • Method Details

    • initialize

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