This content has been marked as final. Show 3 replies
org.hibernate.Session session = (Session) entityManager.getDelegate();
to get the Hibernate Session out and use the Criteria API. Yes, this does make your application non-portable to other JPA implementations, but that is the price you pay.
I haven't looked into the delegate/criteria stuff but my lazy-man's way of doing this is:
List<Customer> customers = entityManager.createQuery("select c from Customer as c "+ " where c.customerId >= :minCustomerId"+ " and c.customerId <= :maxCustomerId") .setParameter("minCustomerId", selectedCustomer==null?Long.MIN_VALUE:selectedCustomer.customerId) .setParameter("maxCustomerId", selectedCustomer==null?Long.MAX_VALUE:selectedCustomer.customerId) .getResultList();