Online Hibernate Training just in Rs. 1000

One week online training in Hibernate ORM framework. Learn Hibernate Framework and enhance your skills. Best Online Hibernate training at 90% discount. Join Now!! Offer is valid Only for limited Period!!! Online Training Big Data and Hadoop Training Java Training  

Hibernate criteria query using Min().



Share on Google+Share on Google+

ratna rathor
Hibernate criteria query using Min().
1 Answer(s)      5 years and 2 months ago
Posted in : Hibernate

How to find minimum value in Hibernate criteria query using Projection?

View Answers

June 4, 2012 at 7:45 PM

You can find out minimum value in hibernate criteria by using projection. Projection is an interface and a class in ?org.hibernate.criterion?. For using Projection object in our Criteria, we have to call setProjection method.


package net.roseindia.projection;

import java.util.*;

import net.roseindia.table.Employee;
import net.roseindia.util.HibernateUtil;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Projections;

public class ProjectionMin{
    public static void main(String[] args) {
        SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
        Session session = sessionFactory.openSession();
        Criteria criteria=session.createCriteria(Employee.class);

        List employeeList = (List)criteria.list();

        for(Object employee: employeeList){


Hibernate: select min(this_.salary) as y0_ from employee this_

Description: Here we are finding the minimum salary of employee by using