What am I doing wrong in this Java class? clazz field is allways null. Shouldn't clazz be automatically populated with the type defined on the concrete class?
Thanks!
public abstract class AbstractDAO<E extends Domain, T extends Number> {
protected EntityManager em;
private Class<E> clazz;
public AbstractDAO(final EntityManager em) {
this.em = em;
}
public E find(T id) {
return em.find(clazz, id);
}
public List<E> findAll() {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<E> cq = cb.createQuery(clazz);
Root<E> from = cq.from(clazz);
CriteriaQuery<E> select = cq.select(from);
return em.createQuery(select).getResultList();
}
// other methods
}