Hibernate HQL query by using like operator.

Ads

 
 

Share on Google+Share on Google+

ratna rathor
Hibernate HQL query by using like operator.
1 Answer(s)      4 years and 11 months ago
Posted in : Hibernate

How use like operator in HQL?

Ads
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();
    }
}

Ads









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
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
Advertisements
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
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
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
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
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
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 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
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... as roseindia.net.Hibernateexample. Benefits of Hibernate Query Language is : Learning (HQL) Query
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
like operator
like operator  how to select exact value using like operator in php
LIKE Operator
SQL Like Operator Query Now we want to select the persons name those name... LIKE Operator       The LIKE operator is used for searching  a specified pattern
Hibernate Query Language
Hibernate Query Language           Introduction to Hibernate Query Language Hibernate Query Language or HQL for short is extremely powerful query language. HQL
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
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
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 for  matching strings based
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
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... like 's%'"); In this query we want to find the name which end with h
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
LIKE Operator
Like Operator Query Now we want to select the persons name those name starts... LIKE Operator       The LIKE operator is used for searching  a specified pattern
Mysql Like Operator
Mysql Like Operator       Mysql Like Operator is used to compare a part of string using the % wild... to view data from Table named employee1 using like command: The below Query
Mysql Like Operator
Mysql Like Operator       Mysql Like Operator is used to compare a part of string using...) Query to view data from Table named employee1 using like command
Tutorials   
Java Spring Hibernate Struts Training Hibernate envers revtype values Hibernate envers audit example Hibernate envers example Hibernate envers revinfo table revinfo table sql Hibernate maven dependency example What is the difference between JPA and Hibernate? How to turn off hbm2ddl? Hibernate hbm2ddl.auto values Hibernate table not mapped error - solution Hibernate error class is not mapped Hibernate Envers custom revinfo table Hibernate Envers - REVINFO table doesn't exist How to enable second level cache in Hibernate 5? How to enable second level cache in Hibernate 5? java.lang.IndexOutOfBoundsException: Remember that ordinal parameters are 1-based! org.hibernate.validator cannot be resolved error java.lang.ClassNotFoundException: org.hibernate.cache.TimestampsRegion java.lang.ClassNotFoundException: org.hibernate.cache.TimestampsRegion property hibernate.cache.region.factory_class is not given Hibernate example step by step in Eclipse with MySQL How to make Struts Hibernate and Spring Based Login/Registration Application? What is the use of Hibernate Native SQL? What is the use of Hibernate is used? How to integrate Struts and Hibernate in an application? How to create the program in Java for getting the forgotten Password Form? How to write create JPA Many-to-Many Relationship in Java? What is the DAO Layer in any application? What is Spring Struts Hibernate DAO Layer? How to write Example code for CRUD application in hibernate annotation? Where to update the Hibernate tools? Query conversion convert into hql how to convert sql into hql package org.hibernate.util does not exist C3P0 with Hibernate What do you understand by JPA? Hibernate Query Checker Jpa many to many relationship What do you understand by Hibernate in Java? What are criteria Queries in Hibernate? How to use Associations and Joins in Hibernate? Hibernate 4 Example with Eclipse How to learn Hibernate? What is Hibernate Framework? hibernate faq 15/03/14 hibernate 15/03/2014 Hibernate Criteria Wildcard how to add mulitiple projections this is a hibernate question

Ads

 
Advertisement null

Ads