Q:

How does JPA's @OneToMany know the Generic entity type at runtime

According to the JavaDoc on @OneToMany, you don't need to specify targetEntity if the "collection property is defined using Java generics". On top of this, you don't need to instantiate the collection property at construction time, but can leave it as null. For example:
@OneToMany(mappedBy="student")
private Collection<Qualification> qualification;

However, as I understood Generics and Type Erasure, at runtime all it's possible to see is that this is a Collection and not a Collection of Qualification - because as I understood it the generic type has been erased here already.
How does this work? What am I missing?

A:

Thanks to Thomas W for pointing this out. You can get the Generic type information from Methods and Fields on a class using reflection, using Method.getGenericReturnType() and Field.getGenericType(), which will then give enough information to know what's needed to do here.

