In this example, you will see how to create criteria for date. This example will access record from data, that is greater then or equal to given date. It is like as search by data.
CriteriaDAO.java
package roseindia.hibernateDAO; import java.util.Iterator; import java.util.List; import org.hibernate.criterion.*; import org.hibernate.Criteria; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.cfg.AnnotationConfiguration; import roseindia.model.StudentModel; public class CriteriaDAO { @SuppressWarnings("deprecation") public List<StudentModel> resultData(StudentModel obModel) { SessionFactory sessionFactory = new AnnotationConfiguration() .configure().buildSessionFactory(); Session session = sessionFactory.openSession(); Criteria criteria = session.createCriteria(StudentModel.class).add( Expression.ge("date", obModel.getDate())); List<StudentModel> studentList = criteria.list(); Iterator studentIterator = studentList.iterator(); return studentList; } } |
Advertisements
Ads
Ads