Home Hibernate Examples Criteria Hibernate Criteria Not Like

Ask Questions?

View Latest Questions


 
 

Hibernate Criteria Not Like
Posted on: April 11, 2011 at 12:00 AM
Advertisement
In this tutorial you will learn Hibernate Criteria Not Like

Hibernate Criteria Not Like

The Hibernate Criteria Not like, ignore the matching string given in like parameter.

Criteria criteria=session.createCriteria(Student.class);
	criteria.add(Restrictions.not(Restrictions.like("name", "%R%")));
	List list=criteria.list();

An example of not like is given below, please consider

CriteriaNotLike.java

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

public class CriteriaNotLike{
	public static void main(String []args){
		Session session=HibernateUtil.getSessionFactory().openSession();
		Criteria criteria=session.createCriteria(Student.class);
		criteria.add(Restrictions.not(Restrictions.like("name", "%R%")));
		List list=criteria.list();
		Iterator iterator=list.iterator();
		while(iterator.hasNext()){
			Student student=(Student)iterator.next();
			System.out.println(student.getName());
		}
	}
}

When you run this application it will display message as shown below:

Hibernate: select this_.roll_no as roll1_0_0_, this_.name as name0_0_, this_.course as course0_0_, this_.address as address0_0_ from student this_ where not (this_.name like ?)
Aman
Vikash

Download Complete Source Code

Related Tags for Hibernate Criteria Not Like :


DMCA.com