Introduction To Hibernate Query Language (HQL)

In this tutorial you will learn about Hibernate Query Language.


 

Ads

Tutorials   
How to write hello world example program in Hibernate? How to create one to one relationship in Hibernate 4 with Annotation? How to calculate minimum in Hibernate using the min() Function Hibernate 4.3.4 Released: Hibernate 4.3.4.Final Maven dependency Hibernate 4.3 Hello World: Example How to create SessionFactory in Hibernate 4.3.1? Hibernate 4 Hello World: Example of Hello World program Hibernate 4 create Session Factory: Example of creating Session Factory in Hibernate 4 Hibernate 4.3 and JPA 2.1 Example What is Hibernate in Java? Hibernate Overview and Architecture What is JPA 2.1? Hibernate 4.3.0.Final Maven dependency Hibernate 4.3 ORM Features Hibernate 4.3 Tutorial Hibernate Criteria average example Hibernate Criteria load all objects from table Hibernate Criteria Hibernate beginner tutorial Hibernate Session.delete() Example Hibernate save or update method example Hibernate Load Example Hibernate save Example - Rose India Hibernate 4 tutorials Hibernate Example Step by Step in Eclipse Hibernate Configuration files Setup Hibernate Environment Hibernate Architecture Hibernate Overview Hibernate 4.2 Tutorial Hibernate 4 Annotations Tutorial Hibernate 4 AnnotationSessionFactoryBean hibernate versions hibernate jndi hibernate tomcat hibernate metamodel generator hibernate entity Seam Hibernate C3P0 Hibernate hibernate shard hibernate means temporal hibernate jsf hibernate spring j2ee hibernate spring hibernate encrypted password alias_to_entity_map hibernate temporal jsf spring hibernate hibernate by example hibernate repository hibernate sample code
Ads

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 roseindia.net.HibernateExample is not same as roseindia.net.Hibernateexample.

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 per.name FROM person per WHERE per.id = "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.

Advertisements

Ads
Share on Google+Share on Google+

Introduction To Hibernate Query Language (HQL)

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

Advertisements

 

Discuss: Introduction To Hibernate Query Language (HQL)  

Post your Comment


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

Ads

 

Ads