Site icon Narayana Tutorial

Hibernate HQL Query Language

Different ways to specify hibernate configuration property values

Hibernate HQL Query Language

Hibernate HQL Query Language is one of the query language in the form object object relation mapping query.

In the hibernate data base operations are two types they are

  1. Single row operations
  2. Bulk operations

By using save(), load(), update() method, we can perform single row operation.

In hibernate there are three ways to perform bulk operations they are

  1. HQL (Hibernate Query Language)
  2. Criteria API
  3. Native SQL

HQL Query Language Features

  1. Hibernate queries are database independent queries. So that we can develop persistent logic by using HQL
  2. HQL queries will be written by using pojo class and pojo class member variable
  3. HQL queries very much similar to sql queries. So learning time of HQL is very less.
  4. HQL queries are case in-sensitives but pojo class and member variables are case sensitive.
  5. HQL queries will be converted into SQL queries.
  6. HQL supports operations, expressions, aggregate functions, sub queries, inner queries and so on..
  7. HQL queries allows place holders.
  8. By using HQL we can perform insert, update, delete and select operations. So we can perform DML but we can not perform DDL.

IF you are writing HQL queries we can use the pojo class name instead of table name and we can use pojo class member variables instead of column names.

Example:

SQL:

  1. Select * from STUDENT( table name);
  2. select * from STUDENT where FIRSTNAME like ‘r%’;
  3. select * from STUDENT as sb where sb.hid>100 and sb.hid<200;
  4. select HID,SFIRSTNAME from STUDENT;

HQL:

  1. from studentBean(pojo class);
  2. from studentBean(pojo class) where sfirstname(pojo class variable) like ‘r%’;
  3. from studentBeansb where sb.hid>100 and sb.hid<200;
  4. select hid,sfirstname from studentBean