That's not how generics work in Java.
A generic class (like your DAO) just doesn't know what it
got as its type parameter. To use this type at runtime you
must specify the information explicitly, either as a Class
typed parameter/property, or by use of a factory class (like
AgentFactory) that will implement all type-specific stuff.
A factory instance would then take the place of your "em", or
maybe that of what you obtain from .getCriteriaBuilder(),
except that it won't need the "HERE_MY_GENERIC_CLASS" argument
to it's methods.
> Someone can help me? I'm using CDI Weld to Inject my DAO class with a generic type:
> @Inject
> private DAO<Agent> dao;
>
> And my DAO Class:
> public class DAO<T> {
>
> public T findAll() {
> CriteriaQuery<T> query = em.getCriteriaBuilder()
> .createQuery(HERE_MY_GENERIC_CLASS);
> query.select(query.from(HERE_MY_GENERIC_CLASS));
> return (T) em.createQuery(query).getResultList();
> }
> }
> How can i get at runtime? To make a query.
return type of findAll has already been discussed in other subthread.