diff --git a/hibernate-core/src/main/java/org/hibernate/usertype/ParameterizedType.java b/hibernate-core/src/main/java/org/hibernate/usertype/ParameterizedType.java index 1de4569a92d3..50860c7ff615 100644 --- a/hibernate-core/src/main/java/org/hibernate/usertype/ParameterizedType.java +++ b/hibernate-core/src/main/java/org/hibernate/usertype/ParameterizedType.java @@ -8,18 +8,52 @@ /** * Support for parameterizable types. A {@link UserType} or {@link UserCollectionType} - * may be made parameterizable by implementing this interface. Parameters for a type - * may be set by using a nested type element for the property element in the mapping - * file, or by defining a typedef. + * may be made parameterizable by implementing this interface. Arguments to parameters + * may be specified via {@link org.hibernate.annotations.Type#parameters}. In XML, + * parameters for a type may be set by using a nested type element for the property + * element in the mapping file, or by defining a typedef. + * + * @deprecated This interface provides little type safety, and results in verbosity + * at the use site. A much better approach is now provided by the possibility of + * declaring a {@link UserType} via an intermediate type annotation. + *

For example, we could define a type annotation for the type {@code TimePeriod}: + *

+ * @Type(PeriodType.class) // the type itself
+ * @Target({METHOD, FIELD})
+ * @Retention(RUNTIME)
+ * // the type annotation:
+ * public @interface TimePeriod {
+ *     // member specifying custom configuration
+ *     // affecting the behavior of the UserType:
+ *     boolean days() default false;
+ * }
+ * 
+ *

Then the {@code UserType} implementation receives an instance of the type annotation + * in its constructor: + *

+ * static class PeriodType implements UserType<Period> {
+ *    private final boolean days;
+ *
+ *    // constructor configures the UserType from
+ *    // information in the annotation instance:
+ *    PeriodType(TimePeriod timePeriod) {
+ *        days = timePeriod.days();
+ *    }
+ *    // implementation of UserType operations:
+ *    ...
+ * }
+ * 
+ *

Therefore, use of {@code ParameterizedType} is no longer encouraged. * * @see org.hibernate.annotations.Type#parameters * * @author Michael Gloegl */ +@Deprecated(since = "7.3") public interface ParameterizedType { - /** - * Gets called by Hibernate to pass the configured type parameters to - * the implementation. - */ - void setParameterValues(Properties parameters); + /** + * Gets called by Hibernate to pass the configured type parameters to + * the implementation. + */ + void setParameterValues(Properties parameters); }