I have created hierarchy of interface and classes using generic and messed up everything.
Topmost class is AbstractJpaEntity which is extended by all domain entity
This is a solution
public TO getTo() throws Exception {
if(to == null) {
try {
to = ((Class) ((ParameterizedType) this.getClass().getGenericSuperclass())
.getActualTypeArguments()[0]).newInstance();
} catch(ClassCastException cce) {
cce.printStackTrace();
to = ((Class) ((ParameterizedType) (((Class) this.getClass()
.getAnnotatedSuperclass().getType()).getGenericSuperclass()))
.getActualTypeArguments()[0]).newInstance();
}
}
return to;
}