For example, for example:
List<T> results = em.createQuery("SELECT t FROM TABLE t", T.class) .getResultList();
With parameters:
List<T> results = em.createQuery("SELECT t FROM TABLE t where t.value = :value1") .setParameter("value1", "some value").getResultList();
For one result, replace getResultList()
with getSingleResult()
:
T entity = em.createQuery("SELECT t FROM TABLE t where t.uniqueKey = :value1") .setParameter("value1", "KEY1").getSingleResult();
Another way is to use the criteria API.
source share