Home Hibernate Examples Criteria Hibernate Criteria Case Insensitive

Ask Questions?

View Latest Questions


 
 

Hibernate Criteria Case Insensitive
Posted on: April 7, 2011 at 12:00 AM
Advertisement
In this tutorial you will learn Hibernate Criteria Case Insensitive

Hibernate Criteria Case Insensitive

The Case Insensitive ignores the case of  the latter. It Selects all the records of the table related to the given parameters

Criteria criteria = session.createCriteria(Student.class);
	criteria.add(Restrictions.eq("name", "ramesh").ignoreCase());
	List list = criteria.list();

An example of Case insensitive is given below please consider it

CriteriaCaseInSensitive.java

package net.roseindia.main;

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;
import java.util.*;

public class CriteriaCaseInSensitive {
	public static void main(String[] args) {
		try {
			Session session = HibernateUtil.getSessionFactory().openSession();
			Criteria criteria = session.createCriteria(Student.class);
			criteria.add(Restrictions.eq("name", "ramesh").ignoreCase());
			List list = criteria.list();
			Iterator listIterator = list.iterator();
			while (listIterator.hasNext()) {
				Student student = (Student) listIterator.next();
				System.out.println(student.getName());
			}
		} catch (HibernateException e) {
			e.printStackTrace();
		}
	}
}

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 lower(this_.name)=?
Ramesh
Ramesh

Download complete Source Code

Related Tags for Hibernate Criteria Case Insensitive:


DMCA.com