Hibernate Criteria


Hibernate Criteria

RDBMS tables can be manipulated in a variety of ways using Hibernate. You may build a criteria query object programmatically using the Criteria API, which allows you to apply filtration rules and logical conditions.

Create Criteria objects using the createCriteria() function of the Hibernate Session interface.

Criteria and restrictions

You can add restrictions to a criterion query by using the add() function on the Criteria object.

Using criteria to create a pagination system

There are two kinds of pagination available in the Criteria interface.

  • Public Criteria setFirstResult(int firstResult): Row 0 is represented by an integer when this method is called, while a string characterizes all other rows.
  • Public Criteria setMaxResults(int maxResults): Maximize the number of objects retrieved by Hibernate with this method.

Two methods can be combined to create a paging component in a web or Swing application by combining them.

Finding Information by Sorting the Results

To sort your result set either ascendingly or descendingly, the Criteria API includes org.hibernate.criterion.Order.

Aggregations & Projections

The org.hibernate.criterion.Projections class is provided by the Criteria API and can be used to determine the average, maximum, or minimum of property values. There are various static factory methods for