Package org.hibernate.annotations

Annotation Interface Type


@Target({METHOD,FIELD,ANNOTATION_TYPE})@Retention(RUNTIME)public @interfaceType
Specifies a customUserType for the annotated attribute mapping. This annotation may be applied:
  • directly to a property or field of an entity to specify the custom type of the property or field,
  • indirectly, as a meta-annotation of an annotation type that is then applied to various properties and fields, or
  • by default, via aregistration.

For example, as an alternative to:

 @Type(MonetaryAmountUserType.class) BigDecimal amount;

we may define an annotation type:

 @Retention(RUNTIME) @Target({METHOD,FIELD}) @Type(MonetaryAmountUserType.class) public @interface MonetaryAmount {}

and then write:

 @MonetaryAmount BigDecimal amount;

which is much cleaner.

The use of aUserType is usually mutually exclusive with the compositional approach ofJavaType andJdbcType.

See Also:
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    Class<? extendsUserType<?>>
    The class which implementsUserType.
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    Parameters to be injected into the custom type after it is instantiated.
  • Element Details

    • parameters

      Parameter[] parameters
      Parameters to be injected into the custom type after it is instantiated. TheUserType implementation must implementParameterizedType to receive the parameters.
      Default:
      {}