开发者

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

开发者 https://www.devze.com 2022-12-08 15:48 出处:网络
Given a simple entity relationship: @Entity public class Single { @OneToMany public Set<Multiple&g开发者_开发百科t; multiples;

Given a simple entity relationship:

@Entity
public class Single {

  @OneToMany
  public Set<Multiple&g开发者_开发百科t; 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.


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();
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号