Share on Google+Share on Google+

Introduction To Hibernate Query Language (HQL)

In this tutorial you will learn about Hibernate Query Language.

Introduction To Hibernate Query Language (HQL)

In this tutorial you will learn about Hibernate Query Language.

HQL is an abbreviation of Hibernate Query Language. It is a powerful query language, inspired by SQL that the Hibernate uses. When looking a HQL it is as similar to SQL but the HQL is different from SQL, HQL is fully object-oriented and it supports inheritance, polymorphism, abstraction. Queries in HQL are case-insensitive excluding the name of classes of java and the properties. for example in query WHerE is as same to whERe but a class name is not same as

Benefits of Hibernate Query Language is :

  1. Learning (HQL) Query in Hibernate is easy.
  2. HQL uses the (.) extension as it is used in object-orientation.
  3. Different SQL databases can be accessed by a single language provided by the HQL with a little different kind of SQL.
  4. HQL supports for relational operations. Using HQL a SQL query is allowed to be represented as an object form because in HQL rather tables and columns Classes and properties are used.
  5. HQL returns result as Object, this feature of HQL reduces the process of creation of an object and population of data from ResultSet.
  6. HQL provides database independent query writing.

Example :

In this example I will write a SQL query and a corresponding HQL query which will demonstrate you how a HQL is looking as same as SQL and how both are different. Let's suppose there is a table 'person' with their fields 'Id', 'Name', 'PersonType' having some value.

1. Writing a query in SQL

SELECT name FROM person WHERE id = "4"

2. A corresponding HQL query can be written as :

SELECT FROM person per WHERE = "4"

Some of the common HQL queries statements / clause are :

  • select
  • from
  • where
  • group by
  • order by
  • insert
  • update
  • delete

Each of the above statements / clause is explained individually. In the next section of this tutorial.



Posted on: February 24, 2012 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: Introduction To Hibernate Query Language (HQL)  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image