
How to check for case sensitive equals 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", "Roxi"));
List<Employee> employeeList = new ArrayList<Employee>();
employeeList = criteria.list();
Iterator it = employeeList.iterator();
while ( it.hasNext()) {
Employee employee = (Employee) it.next();
System.out.println("Name : "+employee.getName());
System.out.println("Salary : "+employee.getSalary());
System.out.println("Date of Join : "+employee.getDateOfJoin()); }
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=?
Name : Roxi
Salary : 220000
Date of Join : 2001-02-03 00:00:00.0
Description : Hibernate Criteria API provides an easy way of building dynamic query on the persistence database. Here we are listing the detail of employee whose name is equal to ?Roxi?. For that you can use criteria.add(Restrictions.eq("name", "Roxi")). It checks name is equal to ?Roxi? or not and corespnding to that printing the detail of employee.
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.