Home Hibernate Examples Criteria Restrictions Hibernate criteria restrictions.between

Ask Questions?

View Latest Questions


 
 

Hibernate criteria restrictions.between
Posted on: April 8, 2011 at 12:00 AM
Advertisement
Hibernate criteria restrictions.between

Hibernate criteria restrictions.between

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; } }

Download Code

Related Tags for Hibernate criteria restrictions.between:


DMCA.com