try {
Object idf = PersistenceSessionUtil.createSession();
EntityManager session = PersistenceSessionUtil.getSession();
EntityTransaction tx = session.getTransaction();
tx.begin();
CriteriaBuilder cb = session.getCriteriaBuilder();
CriteriaQuery<Rooms> cq = cb.createQuery(Rooms.class);
Root<Rooms> c = cq.from(Rooms.class);
Predicate condition = cb.equal(c.get("deleted"), "false");
Predicate subCondition = cb.equal(c.get("externalRoomType"), externalRoomType);
cq.where(condition, subCondition);
cq.distinct(asc);
if (asc){
cq.orderBy(cb.asc(c.get(orderby)));
} else {
cq.orderBy(cb.desc(c.get(orderby)));
}
TypedQuery<Rooms> q = session.createQuery(cq);
q.setFirstResult(start);
q.setMaxResults(max);
List<Rooms> ll = q.getResultList();