
What is Case-insensitive ordering in Hibernate Criteria?

The Case Insensitive ignores the case of the latter. Ordering means you can sort your record either in ascending or descending order By using Hibernate Criteria.
Create hibernate configuration file (hibernate.cfg.xml) and save it in the same folder where you are going to save your source code.
Now create Persistent class Employee.javaâ??Hibernate uses the Plain Old Java Object (POJO) classes to map to the database table. Next create an util class as HibernateUtil.java Here is your MainClass-
Here is a example-
package net.roseindia.main;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import net.roseindia.table.Employee;
import net.roseindia.util.HibernateUtil;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Order;
public class MainClass {
public static void main(String[] args) {
SessionFactory sessionFactory= HibernateUtil.getSessionFactory();
Session session = sessionFactory.openSession();
Criteria criteria =session.createCriteria(Employee.class);
criteria.addOrder(Order.asc("name"));
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_ order by this_.name asc Mandy Ron Roxi Som
Description : Here we are Sorting records in ascending order by name as â??
criteria.addOrder(Order.asc("name"));
You can also order it in descending order as â??
criteria.addOrder(Order.desc("name"));
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.