Get generic attribute type from DynamicParameterizedType#setParameterValues

In Hibernate 5.6 I found a dirty way to get the annotated element to which the @Type was applied by taking a deep dive into the properties provided by DynamicParameterizedType#setParameterValues(Properties parameters) :

Method tam = JavaXMember.class.getSuperclass().getDeclaredMethod("toAnnotatedElement");
tam.setAccessible(true);
AnnotatedElement field = tam.invoke(properties.get(XPROPERTY));

I then would be able to get the generic type of the attribute by doing something like this:

Type attributeType = ((Field)field).getGenericType();

In Hibernate 6.6, due to modularization, I don’t have access to JavaXMember anymore.

Eg. I want to get hands on the generic type representing EnumSet<Name>.

@Type(MyDynamicParameterizedType.class)
@Column(nullable = false)
protected EnumSet<Name> names;

Can someone provide me a solution on how to get the java.lang.reflect.Type of the entity attribute (names in the example) that is annotated with a dynamic parameterized @Type(...) implementation?

You can implement a custom JavaType for EnumSet which will receive a callback JavaType#createJavaType to create a parameterized JavaType. That’s how you get generics information into the JavaType.

Thank you, that looks a lot better than my reflection juggling.

One question though. Is it possible to create a JavaType that supports something similar to CompositeUserType ?

I don’t think so, no.