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); criteria.setProjection(Projections.max(propertyName));
LazyLoading.javaADS_TO_REPLACE_1
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); criteria.setProjection(Projections.max("fee")); 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] |
Advertisements
Ads
Ads