Hibernate criteria max.
Posted on: April 12, 2011 at 12:00 AM
In this tutorial, you will see the use of max method of criteria class in hibernate.

Hibernate criteria max.

Here, we will introduce you to about the max(propertyName) function . It returns the maximum value of column.

Syntax :

Criteria criteria=session.createCriteria(Pojo.class);


package net.roseindia.action;

import java.util.List;
import net.roseindia.bean.StudentBean;
import net.roseindia.util.HibernateUtil;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Projections;

public class CriteiaSort {
	public static void main(String[] args) {
		Session session = HibernateUtil.getSessionFactory().openSession();
		Criteria criteria = session.createCriteria(StudentBean.class);
		List totalFee = criteria.list();
		System.out.println("Total of fee columm : " + totalFee);
When you run this application it will display message as shown below:
Hibernate: select max(this_.fee) as y0_ from studentinfo this_
Maximum value of fee column : [3500]

Download Complete Source Code

Related Tags for Hibernate criteria max.:



Advertisement null