
How to check for case sensitive in Hibernate criteria?

package net.roseindia.main;
import java.util.*;
import net.roseindia.table.Employee;
import net.roseindia.util.ConnectionUtil;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
public class CaseSensitiveComprision{
public static void main(String[] args){
SessionFactory sessionFactory = ConnectionUtil.getSessionFactory();
Session session = sessionFactory.openSession();
Criteria criteria = session.createCriteria(Employee.class);
criteria.add(Restrictions.eq("name", "Ron"));
criteria.add(Restrictions.ge("salary",10000));
List<Employee> employeeList = new ArrayList<Employee>();
employeeList = criteria.list();
Iterator it = employeeList.iterator();
while ( it.hasNext()) {
Employee employee = (Employee) it.next();
System.out.println(employee.getName());
}
session.close();
}
}
Output:
Hibernate: select this_.emp_id as emp1_0_0_, this_.date_of_join as date2_0_0_, this_.name as name0_0_, this_.salary as salary0_0_ from employee this_ where this_.name=? and this_.salary>=?
Ron
Description: Here you are comparing name to ?Ron? by using Restrictions.eq().and also comparing the salary for greater than and equal to ?10000?.
Restrictions.eq() ?used for checking equality .
Restrictions.ge()-used for checking greater than equal.
Restrictions.gt()-comparing for greater value.
Restrictions.le() ?checks for less than equal to
Restrictions.lt() ?comparing for lesser value.
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.