How can I wrap Play/JPA's Model class with a generic Repository?

孤人 提交于 2019-12-05 12:44:02

It does not work because you are calling the static (class) method.

The JPAEnhancer will at run time add the method to your class (User) but there is no polymorphism for types / static methods, it will always call the GenericModel one.

What you can try to do is get the actual parametric type with something like

ParameterizedType superclass = (ParameterizedType) getClass().getGenericSuperclass();
Class<?> aClass = (Class<?>) ((ParameterizedType) superclass).getActualTypeArguments()[0];

and the invoke method on that class..

Hope that helps...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!