bancomat
bancomat

Reputation: 15

JPA Criteria Build how to use Order By Clause with ASC NULLS FIRST

How can I use the "order by" clause with "asc nulls first"?

This is my code:

CriteriaBuilder builder = em.getCriteriaBuilder();

CriteriaQuery<MyClassModel> query = builder.createQuery(MyClassModel.class);

//esprToOrder is a Expression<?> istance that containing the sort field...
query.orderBy(builder.asc(esprToOrder));

TypedQuery<MyClassModel> myQ = em.createQuery(query);

List<MyClassModel> myList = myQ.getResultList();

myList doesn't contain any records with null field sort...

Upvotes: 0

Views: 1827

Answers (1)

Neil Stockton
Neil Stockton

Reputation: 11531

JPA doesn't support specification of "NULLS FIRST|LAST". Some implementations may allow it (by casting to allow extra methods), but it's not part of the JPA spec.

Upvotes: 4

Related Questions