Hibernate Criteria Max Date
Posted on: April 13, 2011 at 12:00 AM
In this tutorial you will learn Hibernate Criteria Max Date

Hibernate Criteria Max Date

An example of getting Max Date from the Hibernate Criteria is given below

CriteriaMaxDate.java

package net.roseindia.main;

import java.util.Iterator;
import java.util.List;

import net.roseindia.bean.Student;
import net.roseindia.util.HibernateUtil;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.ProjectionList;
import org.hibernate.criterion.Projections;

public class CriteriaMaxDate {
	public static void main(String[] args) {
		Session session = HibernateUtil.getSessionFactory().openSession();
		Criteria criteria = session.createCriteria(Student.class);
		ProjectionList projectionList = Projections.projectionList();
		projectionList.add(Projections.max("addmision_date"));
		criteria.setProjection(projectionList);
		List list = criteria.list();
		Iterator iterator = list.iterator();
		System.out.println(iterator.next());
	}
}

When you run this application it will display message as shown below:

ibernate: select max(this_.addmision_date) as y0_ from student this_
2007-07-19 00:00:00.0

Download Complete Source CodeADS_TO_REPLACE_1

Related Tags for Hibernate Criteria Max Date:

Advertisements

Ads

Ads

 
Advertisement null

Ads