Help the world stop coronavirus! Stay home!

Prev Next

Hibernate / Hibernate Interview Questions III

How do I order the selected entity when using CriteriaQuery?

You can define an ORDER BY clause with the orderBy method of the CriteriaQuery interface and the asc or desc method of the CriteriaBuilder interface.

CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Employee> cq = cb.createQuery(Employee.class);
Root<Book> root = cq.from(Employee.class);
cq.orderBy(cb.asc(root.get(Employee_.firstName)));
 
// Execute query with pagination
List<Employee> emplList = em.createQuery(cq).getResultList();

❤Cash Back At Stores you Love !!!❤

Earn your $10 reward when you make your first purchase through Ebates by signing up with clicking below button.

Ebates Coupons and Cash Back

More Related questions...

Show more question and Answers...

Hibernate Caching

Comments & Discussions