How does Hibernate find a generic collection type in a @OneToMany mapping?

Given a simple connection to objects:

@Entity public class Single { @OneToMany public Set<Multiple> multiples; } 

How does Hibernate find out that the common type of multiples is Multiple? This information cannot be found with the standard API Reflection.

I am browsing the source code but donโ€™t know where to start.

+6
java generics hibernate
source share
1 answer

But this can be found using the reflection API. Take a look at Field.getGenericType () :

 Type type = field.getGenericType(); if (type instanceof ParameterizedType) { Type[] genericArguments = ((ParameterizedType) type).getActualTypeArguments(); } 
+7
source share

All Articles