I read somewhere that it’s impossible to get generic interface of a class in run time. so how does hibernate do this? for example in a OneToMany mapping how does hibernate find out the Many part class (using annotation)?
class A{
...
@OneToMany(mapped-by="a")
public List<B> getBs(){
...
}
}
It depends. You can’t ask an instance of a generic type what its type arguments are – but you can get that information from the metadata about classes, method return types etc.
So for example,
Method.getGenericReturnTypereturns aTyperather than aClass<?>, and that lets you get at the relevant information.Sample code: