coalesce
673147Oct 12 2010 — edited Oct 14 2010Hi i normally do this with a SQL query:
SELECT * FROM persons WHERE person_id = coalesce(:mi_variable, person_id);
If i run this query and "pass" value to my bind variable (mi_variable) i get the person who i need with the same id (excepted behaivor), but when i want to recover all the person i send NULL to bind variable (mi_variable) and with coalesce function, all the person_id matchs and i get all of them (excepted behaivor)
But i dont know how to translate this to JPA ( <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>).
CriteriaBuilder cb = entrerpriseManager.getCriteriaBuilder();
CriteriaQuery cq = cb.createQuery();
Root<Persons> per = cq.from(Persons.class);
cq.where( cb.coalesce() )......... <----- at this point i dont know how to do it.
Thanks 4 help!