Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

Hibernate/JPA criteria query

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

try (Session session = sessionFactory.openSession()) {
      CriteriaBuilder criteriaBuilder = session.getCriteriaBuilder();
      CriteriaQuery<Integer> query = criteriaBuilder.createQuery(Integer.class);
      Root<RevisionInfoData> root = query.from(RevisionInfoData.class);
      query
          .select(root.get("revisionNumber"))
          .orderBy(criteriaBuilder.desc(root.get("revisionNumber")));
      return ImmutableSet.copyOf(session.createQuery(query).getResultList());
}
 
PREVIOUS NEXT
Tagged: #criteria #query
ADD COMMENT
Topic
Name
3+9 =