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

Hibernate criteria restrictions.in

In this example, you will see the use of Restrictions class in java. It is used to restrict the retrieval of data from database. Here, you will see the use of in constraint.

Syntax :

Criteria crit=session.createCriteria(model.class).add(Restrictions.in (propertyName, object[] values);

The in constraint has two argument one is property name and another is array of values of property. If the value of array is match to value of data base, then it returns result other wise not.

Structure of database Table....


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 {


public List<StudentModel> resultData(StudentModel obModel) {

SessionFactory sessionFactory = new AnnotationConfiguration()


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

Related Tags for Hibernate criteria restrictions.in:




Advertisement null