0
I have a generic class I’m using to perform queries with JPA Hibernate.
My class is like this:
public class BaseRepositoryImpl<T> implements BaseRepository<T>
The problem is that in some methods, such as the findById
below, I need to explain the Type of the object. And since it is a generic type, it generates an error.
@Override
public T findById(Long id) {
em.getTransaction().begin();
T t = em.find(Class<T>, id); // ERRORRRR
em.getTransaction().commit();
return null;
}
How I must proceed to repair that mistake?
This might help: https://stackoverflow.com/a/9202329
– hkotsubo
It helped a little. But, I had to implement otherwise.
– Thiago Cunha