1

Suppose the following hibernate entity (hibernate not really relevant here):

@TypeDef(
        name = "custom_enum_type",
        typeClass = CustomEnumType.class
)
public static final class MyEntity {
    @Enumerated(STRING)
    @Type(type = "custom_enum_type")
    private MyEnum myEnum;
}

Is it possible to combine all of these annotations into a custom one?

Something like:

@Target({METHOD, FIELD})
@Retention(RUNTIME)
@TypeDef(
        name = "psql_enum",
        typeClass = CustomEnumType.class
)
public @interface EnumeratedCustom {

    EnumType value() default STRING;

    Type type() default @Type(type = "custom_enum_type");

    final class CustomEnumType<T extends Enum<T>> extends org.hibernate.type.EnumType<T> {
        // [...]
    }
}

used like this:

public static final class MyEntity {
    @EnumeratedCustom
    private MyEnum myEnum;
}

The main issue here is that both annotations (@Enumerated and @Type) are targeting fields, not classes


References:

Georgian
  • 8,454
  • 6
  • 43
  • 79

0 Answers0