Hibernate HQL query by using like operator.

Hibernate HQL query by using like operator.

How use like operator in HQL?

View Answers

May 31, 2012 at 6:50 PM

HQL stands for Hibernate Query Language, provided by Hibernate. It is minimal object oriented, similar to SQL.It works like a bridge between database and application. Like operator is used for string pattern matching. The percent character(%) is used before or after the character/substring.

package net.roseindia.main;

import java.util.*;
import net.roseindia.table.Employee;
import net.roseindia.util.ConnectionUtil;
import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;

public class MainClass {
    public static void main(String[] args) {
        SessionFactory sessionFactory = ConnectionUtil.getSessionFactory();
        Session session = sessionFactory.openSession();

        String hql="SELECT emp.name, emp.salary, emp.dateOfJoin from Employee emp WHERE emp.name like 'R%'";
        Query query=session.createQuery(hql);
List<Object> objectList = query.list();
        Iterator iterator = objectList.iterator();
        while(iterator.hasNext()){          
            Object []obj = (Object[])iterator.next();
            System.out.println(obj[0]);
            System.out.println(obj[1]);
            System.out.println(obj[2]);
        }

        session.close();
    }
}









Related Tutorials/Questions & Answers:
Hibernate HQL query by using like operator.
Hibernate HQL query by using like operator.  How use like operator in HQL?   HQL stands for Hibernate Query Language, provided by Hibernate... database and application. Like operator is used for string pattern matching
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
Advertisements
Hibernate Query Language (HQL)
Hibernate Query Language (HQL)  What is Hibernate Query Language (HQL)?   HQL is much like SQL and are case-insensitive, except for the names of the Java Classes and properties. Hibernate Query Language is used
Delete Query using HQL
Delete Query using HQL  Can we write 'AND' with 'WHERE' clause in delete query using HQL? For example: delete from table name where field1... a look at the following link: Hibernate Delete Query
What is Hibernate Query Language (HQL)?
What is Hibernate Query Language (HQL)?  Hi, What is Hibernate Query Language (HQL)? thanks
Delete HQL query - Hibernate
Delete HQL query  Hi I am trying hibernate tutorial. But delete HQL tutorial not working properly. It gives null pointer exception. Query class has method executeUpate() & not executeUpdate(); log4j:WARN No appenders
HQL, Hibernate Query Language
HQL - Hibernate Query Language In this tutorial on HQL we will learn how...? The HQL stands for Hibernate Query Language, which is inspired by the SQL... the programmer to write Query using the persistence entity. The HQL is fully
Hibernate Like Query
This section illustrate hibernate like query with example
How to use AND operator in hibernate Detached criteria query?
How to use AND operator in hibernate Detached criteria query?  How to use AND operator in hibernate Detached criteria query
Hibernate Query Language
; Hibernate Query Language or HQL for short is extremely powerful 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
HQL Query
HQL Query  Hibernate query language: How to use a left join in Hibernate query language. Can somebody help with an example. I am getting a unexpected token error in HQL Query tool If I use joins
How to use AND OR operator in hibernate Detached criteria query?
How to use AND OR operator in hibernate Detached criteria query?  How to use AND OR operator in hibernate Detached criteria query?   You can use AND, OR operator in hibernate detachedCriteria through
HQL query
HQL query  how to select only password based on username using HQL query from login table where uname and paswrd are two column names
HQL in hibernate ? Explain the use of HQL.
HQL in hibernate ? Explain the use of HQL.  What is the HQL in hibernate ? Explain the use of HQL.   HQL stands for Hibernate Query... like SQL.Its query is case-insensitive expect we are using the java class
like operator
like operator  how to select exact value using like operator in php
Introduction To Hibernate Query Language (HQL)
Introduction To Hibernate Query Language (HQL) In this tutorial you will learn about Hibernate Query Language. HQL is an abbreviation of Hibernate Query... (HQL) Query in Hibernate is easy. HQL uses the (.) extension as it is used
LIKE Operator
TableName WHERE ColumnName LIKE pattern SQL Like Operator Query Now we... LIKE Operator       The LIKE operator is used for searching  a specified pattern
How to use OR operator in hibernate Detached criteria query?
How to use OR operator in hibernate Detached criteria query?  How to use OR operator in hibernate Detached criteria query?   You can use OR operator in hibernate detachedCriteria through Restrictions.disjunction
select query using hibernate
select query using hibernate  Hi, can any one tell me to select records from table using hibernate. Thanks   Please visit the following link: Hibernate Tutorials The above link will provide you different
Hibernate Query Language
Hibernate Query Language           Introduction to Hibernate Query Language Hibernate Query Language or HQL for short is extremely powerful query language. HQL
how to search for string using LIKE operator instead of integer?
how to search for string using LIKE operator instead of integer?  ... "table2" details. in other words, my "dbtable.jsp" query should be like this (select * from items where itemname LIKE '"+id). and my detail file "table2.jsp
PHP SQL LIKE Operator
PHP SQL LIKE Operator       This example illustrates how to use the like operator in sql query. The LIKE operator is used in a WHERE clause to search for  matching strings based
Hibernate delete HQL - Hibernate
Hibernate delete HQL  Hi I am trying hibernate tutorial. But delete HQL tutorial not working properly. It gives null pointer exception. Query class has method executeUpate() & not executeUpdate
HQL Query in execute method of Struts2
data from database using hql. And where I need to write the hql query...HQL Query in execute method of Struts2  I am making login page in struts2 and using hibernate . Now I wants to pull user name and password from
PHP SQL LIKE Operator
PHP SQL LIKE Operator This example illustrates how to use the like operator in sql query. The LIKE operator is used in a WHERE clause to search.... $result = mysql_query("select * from emp where name like 's
Hibernate-HQL subquery - Hibernate
Hibernate-HQL subquery  Hi, I need to fetch latest 5 records from a table.My query goes here. select * from (select * from STATUS...) where ROWNUM <=5; -------------------------- I need an equivalent query
AND operator in hibernate.
AND operator in hibernate.  How to use AND operator in hibernate
OR operator in hibernate.
OR operator in hibernate.  How to use OR operator in hibernate
Mysql Like Operator
Mysql Like Operator       Mysql Like Operator is used to compare a part of string using... to view data from Table named employee1 using like command: The below Query is used
Mysql Like Operator
Mysql Like Operator       Mysql Like Operator is used to compare a part of string using the % wild... from Table named employee1 using like command: The below Query is used to return
Hibernate criteria query using Min().
Hibernate criteria query using Min().  How to find minimum value in Hibernate criteria query using Projection?   You can find out minimum value in hibernate criteria by using projection. Projection is an interface
Hibernate criteria query using Max()
Hibernate criteria query using Max()  What is Hibernate criteria query using Max()?   You can find out maximum value in hibernate criteria by using projection. Projection is an interface and a class
Hibernate criteria query using avg()
Hibernate criteria query using avg()  How to calculate average in Hibernate criteria query using Projection?   You can calculate average of any numeric values in hibernate criteria by using projection. Projection
LIKE Operator
WHERE ColumnName LIKE pattern SQL Like Operator Query Now we want... LIKE Operator       The LIKE operator is used for searching  a specified pattern
HQL
HQL  What is the HQL in hibernate ? Explain the use of HQL.   Hi Friend, Please visit on this link....... Hibernate Query Language
sum and avg function using HQL.
sum and avg function using HQL.  How to use sum and avg function in HQL?   HQL supports many aggregate functions. Sum and avg are some...(emp.salary) FROM Employee emp"; Query sumQuery = session.createQuery
Hibernate delete Query
Hibernate delete Query In this tutorial you will learn how to use HQL delete query in Hibernate. In this section we are discussing about the HQL delete query... to use HQL delete query. An example is being given regarding how delete query may
Mysql Like Operator
of pattern matching in select query. The like comparison Operator in SQL allows you... Mysql Like Operator     ... you to understand an  example from 'Mysql Like Operator'.To grasp
Mysql Like Operator
in select query. The like comparison Operator in SQL allows you to match any... Mysql Like Operator      ... an  example from 'Mysql Like Operator'.To grasp this exammple we create
Using Min, Max and Count on HQL.
Using Min, Max and Count on HQL.  How to use Min, Max and Count on HQL
SQL AND Like Operator
SQL AND Like Operator       The SQL AND Like Operator work with WHERE clause to find and search  for a specified pattern in a column of table. The AND Like Operator
Hibernate Query Language
Hibernate Query Language   Explain Hibernate Query Language(HQL) of Hibernate?   Hi Samar, Hibernate Query Language is a library.... Compared with SQL, however, HQL is fully object-oriented and understands notions
HQL Sample
technical stuff very easily. The HQL or Hibernate Query language is very powerful and can be easily used to develop complex query in Java program. HQL is then translated into SQL by the ORM component of Hibernate. HQL is very powerful
How to get unique list in Hibernate using Criteria Query?
How to get unique list in Hibernate using Criteria Query?  Hi, Share me the example code for getting Unique List in Hibernate through Criteria Query? Thanks
Hibernate query - Hibernate Interview Questions
Hibernate query  Hi,In my one interview i face one question that is how to write query without using hql and sql.If any body knows please give the answer thank u
Hibernate Training
Learning Fundamentals of  Hibernate by using the Hibernate persistence engine. How to persist different types of objects using the Hibernate. How to use HQL (Hibernate Query Language) for querying objects
like query and then update or replace
like query and then update or replace   In postgres i use like query... "Small state in wmost Brazil bordered by sw Amazonas, Peru, and Bolivia." with like query i can find text that contains text "wmost" after finding that i want
Hibernate Query - Hibernate
Hibernate Query  Hibernate Query
SQL AND Like Operator
SQL AND Like Operator       The SQL AND Like Operator work with WHERE clause to find and search  for a specified pattern in a column of table. The AND Like Operator
Hibernate Named Native SQL Query using XML Mapping
In this section, you will learn Named Native SQL Query using XML Mapping in Hibernate with an example

Ads