Class CriteriaQueries


  • public class CriteriaQueries
    extends Object
    Utility class for creating Hibernate Criteria queries.
    Implementation Note:
    Suppressing all IntelliJ and Sonar deprecation warnings. We are aware that the Hibernate Criteria API is deprecated.
    • Constructor Summary

      Constructors 
      Constructor Description
      CriteriaQueries()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static org.hibernate.Criteria addOrder​(org.hibernate.Criteria criteria, String orderClause)
      Adds the specified order clause to an existing Criteria, returning the criteria that was passed in.
      static org.hibernate.Criteria distinctCriteria​(org.hibernate.Session session, Class<?> persistentClass)
      Creates a Criteria query for the specified persistent class.
      static org.hibernate.Criteria distinctCriteria​(org.hibernate.Session session, Class<?> persistentClass, String orderClause, String... fetchAssociations)
      Creates a Criteria query for the specified persistent class, with the specified ordering, and setting FetchMode.JOIN on the specified fetchAssociations.
      static org.hibernate.Criteria distinctCriteriaWithFetchAssociations​(org.hibernate.Session session, Class<?> persistentClass, String... fetchAssociations)
      Creates a Criteria query for the specified persistent class and setting FetchMode.JOIN on the specified fetchAssociations.
      static org.hibernate.Criteria distinctCriteriaWithOrder​(org.hibernate.Session session, Class<?> persistentClass, String orderClause)
      Creates a Criteria query for the specified persistent class and the specified HQL order clause.
    • Constructor Detail

      • CriteriaQueries

        public CriteriaQueries()
    • Method Detail

      • distinctCriteria

        public static org.hibernate.Criteria distinctCriteria​(org.hibernate.Session session,
                                                              Class<?> persistentClass,
                                                              String orderClause,
                                                              String... fetchAssociations)
        Creates a Criteria query for the specified persistent class, with the specified ordering, and setting FetchMode.JOIN on the specified fetchAssociations.
        Parameters:
        session - the Hibernate session
        persistentClass - the class for which to create a criteria query
        orderClause - the order specification
        fetchAssociations - one or more associations to fetch via a join
        Returns:
        a Criteria which you can build upon
        See Also:
        addOrder(Criteria, String), distinctCriteriaWithFetchAssociations(org.hibernate.Session, Class, String...)
      • distinctCriteriaWithOrder

        public static org.hibernate.Criteria distinctCriteriaWithOrder​(org.hibernate.Session session,
                                                                       Class<?> persistentClass,
                                                                       String orderClause)
        Creates a Criteria query for the specified persistent class and the specified HQL order clause.
        Parameters:
        session - the Hibernate session
        persistentClass - the class for which to create a criteria query
        orderClause - the order specification
        Returns:
        a {code Criteria} which you can build upon
        See Also:
        addOrder(Criteria, String)
      • distinctCriteriaWithFetchAssociations

        public static org.hibernate.Criteria distinctCriteriaWithFetchAssociations​(org.hibernate.Session session,
                                                                                   Class<?> persistentClass,
                                                                                   String... fetchAssociations)
        Creates a Criteria query for the specified persistent class and setting FetchMode.JOIN on the specified fetchAssociations.
        Parameters:
        session - the Hibernate session
        persistentClass - the class for which to create a criteria query
        fetchAssociations - one or more associations to fetch via a join
        Returns:
        a Criteria which you can build upon
      • distinctCriteria

        public static org.hibernate.Criteria distinctCriteria​(org.hibernate.Session session,
                                                              Class<?> persistentClass)
        Creates a Criteria query for the specified persistent class.
        Parameters:
        session - the Hibernate session
        persistentClass - the class for which to create a criteria query
        Returns:
        a Criteria which you can build upon
      • addOrder

        public static org.hibernate.Criteria addOrder​(org.hibernate.Criteria criteria,
                                                      String orderClause)
        Adds the specified order clause to an existing Criteria, returning the criteria that was passed in.

        The orderClause should contain a comma-separated list of properties optionally followed by an order designator, which must be asc or desc. If neither ascending nor descending is specified, ascending order is used. For example, the order clause for listing people by descending date of birth, then ascending last name, and finally ascending first name is:

         dateOfBirth desc, lastName, firstName
         
        Parameters:
        criteria - an existing Criteria to add ordering to
        orderClause - the order specification
        Returns:
        the same criteria instance passed in, to allow building upon it