Home Hibernate Examples Criteria Restrictions Hibernate criteria restrictions.or

Ask Questions?

View Latest Questions


 
 

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

Hibernate criteria restrictions.or

In this tutorial, you will see the use of or constraints of Restricatrions class in java. It is available in org.hibernate.criteria package. 

Syntax :

Criteria crit=session.createCriteria(model.class).add(Restrictions.ir(Restrictions(propertyName, propertyValue),Restrictions(propertyName, propertyValue));

The or constraints works as logical or in hibrenate.

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.or:


DMCA.com