Using an EntityManager in an abstract class, I am trying to create a function that returns a list of all the results in a table from the entity class. Each table has its own persistence class that inherits from the abstract class. So far I have:
public abstract class AbstractFacade<T> {
private Class<T> entityClass;
...
public List<T> findAll() {
javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery();
cq.select(cq.from(entityClass));
return getEntityManager().createQuery(cq).getResultList();
}
}
That works for JPA 2.0 but I just discovered that my server is restricted to JPA 1.0 which doesn’t support getCriteriaBuilder() or createQuery(CriteriaQuery cq)
Is there a way I can re-factor my code to do relatively the same thing with a mechanism that exists in JPA 1.0?
You can use the following approach:
Note that it won’t work if you override logical entity names (
@Entity(name = ...)), but it’s not a common case in practice.