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()); } }
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
Advertisements
Ads
Ads