Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Given a simple entity relationship:

@Entity
public class Single {

  @OneToMany
  public Set<Multiple> multiples;
}

How does Hibernate find out that the generic type of multiples is Multiple? This information is impossible to find with the standard Reflection API.

I'm looking through the source code, but don't really know where to start.

like image 785
Mwanji Ezana Avatar asked Oct 08 '09 20:10

Mwanji Ezana


1 Answers

But it is possible to find out using reflection API. Take a look at Field.getGenericType():

Type type = field.getGenericType();
if (type instanceof ParameterizedType) {
  Type[] genericArguments = ((ParameterizedType) type).getActualTypeArguments();
}
like image 165
ChssPly76 Avatar answered Sep 21 '22 03:09

ChssPly76