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.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;

public class CriteriaBetween {

	@SuppressWarnings("unchecked")
	public static void main(String[] args) {

		Session session = HibernateUtil.getSessionFactory().openSession();

		Object object;

		try {
			// Creating Criteria Object
			Criteria criteria = session.createCriteria(Student.class);
			criteria.add(Restrictions.like("name", "John"));
			criteria.add(Restrictions.between("rollNo", 0, 5));
			List list=criteria.list();
			Iterator result=list.iterator();
			while(result.hasNext()){
				object=result.next();
				System.out.println(((Student) object).getRollNo()+"\t"+ ((Student) object).getName()+"\t"+ ((Student) object).getCourse()+"\t"+ ((Student) object).getAddress());
			}
			
		} catch (HibernateException e) {

			e.printStackTrace();
		} finally {
			session.close();
		}

	}
}
