try {
Object idf = PersistenceSessionUtil.createSession();
EntityManager session = PersistenceSessionUtil.getSession();
EntityTransaction tx = session.getTransaction();
tx.begin();
CriteriaBuilder cb = session.getCriteriaBuilder();
CriteriaQuery<Users> cq = cb.createQuery(Users.class);
Root<Users> c = cq.from(Users.class);
Expression<String> literal = cb.literal((String) "%"
+ searchstring + "%");
// crit.add(Restrictions.ilike(searchcriteria, "%" +
// searchstring + "%"));
Path<String> path = c.get(searchcriteria);
Predicate predicate = cb.like(path, literal);
Predicate condition = cb.notEqual(c.get("deleted"), "true");
cq.where(condition, predicate);
cq.distinct(asc);
if (asc) {
cq.orderBy(cb.asc(c.get(orderby)));
} else {
cq.orderBy(cb.desc(c.get(orderby)));
}
TypedQuery<Users> q = session.createQuery(cq);
q.setFirstResult(start);
q.setMaxResults(max);
List<Users> contactsZ = q.getResultList();