HHH-15926 allow @Type and @CompositeType to be applied as meta-annotations
this was almost zero work, the implementation was already there
This commit is contained in:
parent
bc79368cd6
commit
51f1e2f5bd
|
@ -11,17 +11,28 @@ import java.lang.annotation.Target;
|
|||
|
||||
import org.hibernate.usertype.CompositeUserType;
|
||||
|
||||
import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
|
||||
import static java.lang.annotation.ElementType.FIELD;
|
||||
import static java.lang.annotation.ElementType.METHOD;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
/**
|
||||
* Applies a custom {@link CompositeUserType} for the attribute mapping.
|
||||
* Specifies a custom {@link CompositeUserType} for the annotated attribute
|
||||
* mapping. Just like the {@link Type @Type} annotation, this annotation may
|
||||
* be applied:
|
||||
* <ul>
|
||||
* <li>directly to a property or field of an entity to specify the custom
|
||||
* type of the property or field,
|
||||
* <li>indirectly, as a meta-annotation of an annotation type that is then
|
||||
* applied to various properties and fields, or
|
||||
* <li>by default, via a {@linkplain CompositeTypeRegistration registration}.
|
||||
* </ul>
|
||||
*
|
||||
* @see CompositeUserType
|
||||
* @see CompositeTypeRegistration
|
||||
* @see Type
|
||||
*/
|
||||
@Target({METHOD, FIELD})
|
||||
@Target({METHOD, FIELD, ANNOTATION_TYPE})
|
||||
@Retention(RUNTIME)
|
||||
public @interface CompositeType {
|
||||
/**
|
||||
|
|
|
@ -23,7 +23,7 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
|||
* {@linkplain jakarta.persistence.Embeddable embeddable} class.
|
||||
* <p>
|
||||
* May be overridden for a specific entity field or property using
|
||||
* {@link CompositeType}.
|
||||
* {@link CompositeType @CompositeType}.
|
||||
*
|
||||
* @see CompositeUserType
|
||||
* @see CompositeType
|
||||
|
|
|
@ -11,20 +11,48 @@ import java.lang.annotation.Target;
|
|||
|
||||
import org.hibernate.usertype.UserType;
|
||||
|
||||
import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
|
||||
import static java.lang.annotation.ElementType.FIELD;
|
||||
import static java.lang.annotation.ElementType.METHOD;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
/**
|
||||
* Specifies a custom {@link UserType} for the annotated attribute mapping.
|
||||
* This annotation may be applied:
|
||||
* <ul>
|
||||
* <li>directly to a property or field of an entity to specify the custom
|
||||
* type of the property or field,
|
||||
* <li>indirectly, as a meta-annotation of an annotation type that is then
|
||||
* applied to various properties and fields, or
|
||||
* <li>by default, via a {@linkplain TypeRegistration registration}.
|
||||
* </ul>
|
||||
* For example, as an alternative to:
|
||||
* <pre>{@code
|
||||
* @Type(MonetaryAmountUserType.class)
|
||||
* BigDecimal amount;
|
||||
* }</pre>
|
||||
* we may define an annotation type:
|
||||
* <pre>{@code
|
||||
* @Retention(RUNTIME)
|
||||
* @Target({METHOD,FIELD})
|
||||
* @Type(MonetaryAmountUserType.class)
|
||||
* public @interface MonetaryAmount {}
|
||||
* }</pre>
|
||||
* and then write:
|
||||
* <pre>{@code
|
||||
* @MonetaryAmount
|
||||
* BigDecimal amount;
|
||||
* }</pre>
|
||||
* which is much cleaner.
|
||||
* <p>
|
||||
* This is usually mutually exclusive with the compositional approach of
|
||||
* {@link JavaType}, {@link JdbcType}, etc.
|
||||
* The use of a {@code UserType} is usually mutually exclusive with the
|
||||
* compositional approach of {@link JavaType} and {@link JdbcType}.
|
||||
*
|
||||
* @see UserType
|
||||
* @see TypeRegistration
|
||||
* @see CompositeType
|
||||
*/
|
||||
@Target({METHOD, FIELD})
|
||||
@Target({METHOD, FIELD, ANNOTATION_TYPE})
|
||||
@Retention(RUNTIME)
|
||||
public @interface Type {
|
||||
/**
|
||||
|
|
|
@ -22,7 +22,7 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
|||
* to be used by default for all references to a particular basic type.
|
||||
* <p>
|
||||
* May be overridden for a specific entity field or property using
|
||||
* {@link Type}.
|
||||
* {@link Type @Type}.
|
||||
*
|
||||
* @see UserType
|
||||
* @see Type
|
||||
|
|
|
@ -155,6 +155,7 @@ import static org.hibernate.boot.model.internal.BinderHelper.getPropertyOverridd
|
|||
import static org.hibernate.boot.model.internal.BinderHelper.getRelativePath;
|
||||
import static org.hibernate.boot.model.internal.BinderHelper.hasToOneAnnotation;
|
||||
import static org.hibernate.boot.model.internal.BinderHelper.makeIdGenerator;
|
||||
import static org.hibernate.boot.model.internal.HCANNHelper.findAnnotation;
|
||||
import static org.hibernate.boot.model.internal.HCANNHelper.findContainingAnnotation;
|
||||
import static org.hibernate.boot.model.internal.InheritanceState.getInheritanceStateOfSuperEntity;
|
||||
import static org.hibernate.boot.model.internal.InheritanceState.getSuperclassInheritanceState;
|
||||
|
@ -1804,7 +1805,7 @@ public final class AnnotationBinder {
|
|||
final XClass returnedClass = inferredData.getClassOrElement();
|
||||
|
||||
if ( property != null ) {
|
||||
final CompositeType compositeType = property.getAnnotation( CompositeType.class );
|
||||
final CompositeType compositeType = findAnnotation( property, CompositeType.class );
|
||||
if ( compositeType != null ) {
|
||||
return compositeType.value();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue