Hibernate Criteria Case Insensitive Search.

Hibernate Criteria Case Insensitive Search.

How to use Case Insensitive Search in Hibernate?

View Answers

May 29, 2012 at 6:32 PM

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

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-

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.Restrictions;

public class MainClass {
    public static void main(String[] args) {
        SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
        Session session = sessionFactory.openSession();
        Criteria criteria =session.createCriteria(Employee.class);
        criteria.add(Restrictions.like("name", "r%"));
        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();
    }
}

Description: - Hibernate criteria is used here as alternative to HQL. The Criteria interface can be obtained using the Session.createCriteria() method.

criteria.add(Restrictions.like("name", "r%"));
//It selects all names that start with â??râ?? character without caring of case sensitivity.

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 like ?
Ron
Roxi

You can also Use Restrictions.eq().ignoreCase(). It checks equality, ignoring the case. Ex.

criteria.add(Restrictions.eq("name", "ron").ignoreCase());









Related Tutorials/Questions & Answers:
Hibernate Criteria Case Insensitive Search.
Hibernate Criteria Case Insensitive Search.  How to use Case Insensitive Search in Hibernate?   The Case Insensitive ignores the case...()); } session.close(); } } Description: - Hibernate criteria is used here
Case-insensitive ordering using Hibernate Criteria.
Case-insensitive ordering using Hibernate Criteria.  What is Case-insensitive ordering in Hibernate Criteria
Advertisements
Hibernate Criteria Case Insensitive
Hibernate Criteria Case Insensitive The Case Insensitive ignores the case... = criteria.list(); An example of Case insensitive is given below please consider... parameters Criteria criteria = session.createCriteria(Student.class
Case-insensitive equals using Hibernate Criteria.
Case-insensitive equals using Hibernate Criteria.  How to use Case-insensitive equals with Hibernate Criteria?   The Case Insensitive ignores the case of the latter. It Selects all the records of the table related
Case-insensitive search using Hibernate Query Language(HQL).
Case-insensitive search using Hibernate Query Language(HQL).  What is Case-insensitive search using Hibernate Query Language
indexof case insensitive java
indexof case insensitive java  Hi, I have to use the indexOf function on String class in Java. I am looking for indexof case insensitive java example. Share the code with me. Thanks (adsbygoogle = window.adsbygoogle
Case-sensitive equals using Hibernate Criteria.
Case-sensitive equals using Hibernate Criteria.  How to check for case sensitive equals in Hibernate criteria?   package net.roseindia.main... : 220000 Date of Join : 2001-02-03 00:00:00.0 Description : Hibernate Criteria API
ModuleNotFoundError: No module named 'case_insensitive_dict'
ModuleNotFoundError: No module named 'case_insensitive_dict'  Hi...: No module named 'case_insensitive_dict' How to remove the ModuleNotFoundError: No module named 'case_insensitive_dict' error? Thanks   Hi
ModuleNotFoundError: No module named 'case_insensitive_dict'
ModuleNotFoundError: No module named 'case_insensitive_dict'  Hi...: No module named 'case_insensitive_dict' How to remove the ModuleNotFoundError: No module named 'case_insensitive_dict' error? Thanks   Hi
Examples of Hibernate Criteria Query
Criteria Case Insensitive Hibernate Criteria Join Hibernate Criteria Join...Example code and running projects of Hibernate Criteria Query Here are examples of Criteria Query in Hibernate and all the examples comes with the running
ModuleNotFoundError: No module named 'odoo10-addon-auth-user-case-insensitive'
ModuleNotFoundError: No module named 'odoo10-addon-auth-user-case-insensitive...: ModuleNotFoundError: No module named 'odoo10-addon-auth-user-case-insensitive' How...-case-insensitive' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'odoo11-addon-auth-user-case-insensitive'
ModuleNotFoundError: No module named 'odoo11-addon-auth-user-case-insensitive...: ModuleNotFoundError: No module named 'odoo11-addon-auth-user-case-insensitive' How...-case-insensitive' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'odoo12-addon-auth-user-case-insensitive'
ModuleNotFoundError: No module named 'odoo12-addon-auth-user-case-insensitive...: ModuleNotFoundError: No module named 'odoo12-addon-auth-user-case-insensitive' How...-case-insensitive' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'odoo12-addon-auth-user-case-insensitive'
ModuleNotFoundError: No module named 'odoo12-addon-auth-user-case-insensitive...: ModuleNotFoundError: No module named 'odoo12-addon-auth-user-case-insensitive' How...-case-insensitive' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'odoo13-addon-auth-user-case-insensitive'
ModuleNotFoundError: No module named 'odoo13-addon-auth-user-case-insensitive...: ModuleNotFoundError: No module named 'odoo13-addon-auth-user-case-insensitive' How...-case-insensitive' error? Thanks   Hi, In your python
Hibernate Criteria Examples
Hibernate Criteria Count Hibernate Criteria Count Distinct Hibernate Criteria Case Insensitive Hibernate Criteria For Date Hibernate Criteria Distinct...Hibernate Criteria Examples In this section we are giving many example
Hibernate Criteria Lower
Hibernate Criteria Lower The Hibernate Criteria Lower Ignore a the case. You... = HibernateUtil.getSessionFactory().openSession(); Criteria criteria... this application it will display message as shown below: Hibernate: select
Criteria in Hibernate
Criteria in Hibernate  What is Criteria in Hibernate?   Criteria is a simplified API for retrieving entities by composing Criterion objects. This is a very convenient approach for functionality like "search" screens
Hibernate case sensitive comparison.
Hibernate case sensitive comparison.  How to check for case sensitive in Hibernate criteria?   package net.roseindia.main; import...(); Session session = sessionFactory.openSession(); Criteria criteria
Hibernate criteria disjunction.
Hibernate criteria disjunction.  What is criteria disjunction in hibernate
How to write the new Criteria Query in my case?
How to write the new Criteria Query in my case?  Hi expert, I am using hibernate 5.2.1. However, I do not know how to change the following deprecated code into the new Criteria Query. My old code is : try{ tx
Hibernate Criteria And Or Example
Hibernate Criteria And Or Example  Hibernate Criteria And Or Example I want example of Hibernate Criteria And Or in Java Thanks   Example of Hibernate Criteria And Or Criteria Check the tutorial Hibernate Criteria
Hibernate Criteria
In this tutorial we are going to discuss Hibernate Criteria with example
Hibernate Criteria Or
In this section we are going to discuss Hibernate Criteria Or with example
Hibernate-Criteria - Hibernate
Hibernate-Criteria  Hi friends, I am new to hibernate. Im learning it. When im using Criteria im getting exception tht "Criteria cannot... for more information. http://www.roseindia.net/hibernate/hibernate-between
Hibernate criteria delete Example
Hibernate criteria delete Example  How to use the delete criteria in Hibernate? thanks
Hibernate criteria by id.
Hibernate criteria by id.  How to display record by using criteria by id in Hibernate
Hibernate Criteria Count Example
Hibernate Criteria Count Example  Example of Hibernate Criteria Count. Check the tutorial Hibernate Criteria Count. Check the Latest tutorials, articles and examples of Hibernate Framework. Thanks
Hibernate criteria date Example
Hibernate criteria date Example  Example of Hibernate criteria date. Check the tutorial hibernate criteria date. Check the Latest tutorials, articles and examples of Hibernate Framework. Thanks
Hibernate Query Language
query language. HQL is much like SQL  and are case-insensitive, except... be used while using Hibernate. These are Query By Criteria (QBC) and Query BY Example... Hibernate Query Language      
Hibernate Search
Hibernate Search  Where to learn Hibernate Search module? Thanks   Hi, Check the tutorial: Hibernate Search - Complete tutorial on Hibernate Search Thanks
Hibernate Criteria With Collections Example
Hibernate Criteria With Collections Example  Good code of Hibernate... Hibernate Criteria With Collections in your Java project. Check the tutorial Hibernate Criteria With Collections . Check the Latest tutorials, articles
Hibernate Criteria And Restrictions Example
Hibernate Criteria And Restrictions Example  How to use Criteria And Restrictions in Hibernate? Thanks   I will provide you the example code of Hibernate Criteria And Restrictions. Check the tutorial Hibernate
Hibernate Criteria Wildcard
Hibernate Criteria Wildcard   How to write Criteria Query in Hibernate that uses the Wildcards?   Hello, Check the example Hibernate Criteria Wildcard. Thanks
What are criteria Queries in Hibernate?
What are criteria Queries in Hibernate?  Just explain me what is Criteria Query in Hibernate with examples? Thanks   Criteria queries are very helpful in hibernate for queries based on certain criteria. Check
What is Hibernate Criteria Transformer?
What is Hibernate Criteria Transformer?  Hi, Can anyone explain me about the Hibernate Criteria Transformer? I need good example of Hibernate Criteria Transformer . Thanks   Hi, check the example Hibernate Criteria
Hibernate criteria for date. Example
Hibernate criteria for date. Example  What to use the Hibernate criteria for date in Hibernate based application? I want example of Hibernate criteria for date in Hibernate orm. Thanks   Example of Hibernate criteria
Hibernate Criteria Queries - Hibernate
Hibernate Criteria Queries  Can I use the Hibernate Criteria Query...().buildSessionFactory(); session = sessionFactory.openSession(); Criteria crit... Configuration(); // configuring hibernate SessionFactory
Hibernate criteria average Example
Hibernate criteria average Example   How to find the average in Hibernate? Thanks   Example of finding average on a filed in Hibernate... the tutorial Hibernate criteria avg.. Check the Latest tutorials, articles
Hibernate Criteria Between Example
Hibernate Criteria Between Example  How to use the Between in the Hibernate Query? Share me good example code. Thanks   Example of Hibernate Criteria Between. Check the tutorial Hibernate Criteria Between. Check
Hibernate criteria for date.
Hibernate criteria for date. In this example, you will see how to create criteria for date. This example will access record from data, that is  greater then or equal to given date. It is like as search by data. CriteriaDAO.java
Hibernate Detached Criteria Example
Hibernate Detached Criteria Example  How to use Hibernate Detached Criteria in Java program? What is the use of Hibernate Detached Criteria? Explain... Detached Criteria. Check Latest Hibernate Tutorials and Articles
Hibernate Criteria Wildcard Example
Hibernate Criteria Wildcard Example  Hi, How to write Java program to use the Hibernate Criteria Wildcard query and fetch the data from database I want example of Hibernate Criteria Wildcard which is easy to understand
hibernate criteria disjunction Example
hibernate criteria disjunction Example  I want example of hibernate criteria disjunction. Thanks   Example of hibernate criteria disjunction. Please check the tutorial hibernate criteria disjunction. This tutorial
Hibernate Detached Criteria Example
Hibernate Detached Criteria Example  can anyone share me the source code of using detached Criteria in Hibernate? Thanks   Hi, If you are looking for the Example program of using Hibernate Detached Criteria
Criteria Query Examples in Hibernate
Criteria Query Examples in Hibernate  How to use the Criteria Query in Hibernate? How to select the data using Criteria Query of Hibernate? Thanks... Criteria Query in Hibernate with Examples code. Check the tutorial Criteria Query
Hibernate Criteria Transformer Example
Hibernate Criteria Transformer Example  I want example of Hibernate...   Here I am giving you the link of Hibernate Criteria Transforme example program. Check the tutorial Hibernate Criteria Transformer . Check the Latest
Hibernate Criteria Query Example
Hibernate Criteria Query Example  Hi, How to create Hibernate Criteria Query Examples in Java program? Share me the easy to learn example code. Thanks   Hi, Hibernate Criteria Query is used to selectively find
Hibernate Detached Criteria
This section is good discussion about hibernate detached criteria
Hibernate Criteria Query Example
Hibernate Criteria Query Example In this Example, We will discuss about hibernate criteria query, The interface org.hibernate.Criteria is used to create the criterion for the search. In this example we create a criteria instance

Ads