In this tutorial, you will see the use of between constraints of Restricatrions class in java. It is available in org.hibernate.criteria package.
Syntax :
Criteria crit=session.createCriteria(model.class).add(Restrictions.between(propertyName, minPropertyValues, maxPropertyValues);
The between constraint has three argument one is property name, second is minPropertyValue and third one is maxPropertyValues. It checks, the value of property in database is in between the given values or not.
Structure of database Table....
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.EmpInfo;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(EmpInfo. class).add(Restrictions.in( "fname", new String[] { "bharat", "ankit", "Vinay" }));List<StudentModel> studentList = criteria.list(); Iterator studentIterator = studentList.iterator(); return studentList; } } |
Advertisements
Ads
Ads