Get all updates of Java4s
Follow Us: Email Newsletter

Part 1 Hibernate Query Language Introduction

Hibernate » On Jul 8, 2011 { 7 Comments } By Sivateja

So far we done the operations on single object (single row), here we will see modifications, updates on multiple rows of data (multiple objects) at a time.  In hibernate we can perform the operations on a single row (or) multiple rows at a time, if we do operations on multiple rows at once, then we can call this as bulk operations.

  • HQL is the own query language of hibernate and it is used to perform bulk operations on hibernate programs
  • An object oriented form of SQL is called HQL
  • here we are going to replace table column names  with POJO class variable names and table names with POJO class names in order to get HQL commands


Advantages Of HQL:

  • HQL is database independent, means if we write any program using HQL commands then our program will be able to execute in all the databases with out doing any further changes to it
  • HQL supports object oriented features like Inheritance, polymorphism, Associations(Relation ships)
  • HQL is initially given for selecting object from database and in hibernate 3.x we can do DML operations ( insert, update…) too


Different Ways Of Construction HQL Select

  • If we want to select a Complete Object from the database, we use POJO class reference in place of   *  while constructing the query
  • In this case (select a complete object from the database) we can directly start our HQL command from,  from key word



  • If we want to load the Partial Object from the database that is only selective properties (selected columns) of an objects then we need to replace column names with POJO class variable names.



  • It is also possible to load or select the object from the database by passing run time values into the query,  in this case we can use either ” ? ” symbol or label in an HQL command, the index number of  ” ? ” will starts from zero but not one ( Remember this, little important regarding interview point of view)


  • Here :java4s refers that, java4s is a label(colon ‘:’ symbol represents that its the label)
  • we used to store some values in this label in run time (in our class)

 Next Session HQL part 2

You Might Also Like

  ♦ About Author ♦

Full Stack( Java/J2EE & UI/UX ) Developer and founder of Java4s - Get It Yourself, A popular Java/J2EE Programming Blog. Sign-up for the Email Newsletter for your daily dose of Java tutorials.


7 Responses to “Part 1 Hibernate Query Language Introduction”
  1. bhanu says:

    when to use hibernate criteria query and HQL. Please suggest…

  2. Mai Hung says:

    Hello, java4s team.
    I have a doubt about this advantage.

    “HQL is database independent, means if we write any program using HQL commands then our program will be able to execute in all the databases with out doing any further changes to it ”

    May you explan me or give me a example about this advantage, please?

    Thank you.

  3. Sai Krishna says:

    Awesome website to learn from scratch….

  4. Shivani says:

    Best website i ever have seen :)

  5. Archita patnaik says:

    Thank you Java4s group , for clearing concept from scratch..its really helpful
    Keep rocking…Best website ever ever…

  6. Vijay Jagtap says:

    Thank U for Devloped this site.
    it is very usefull to student who are fresher in Hibernate.

  7. Atul says:

    Thank u for writing tutorial…

    Best website …


By posting your answer, you agree to our comments policy.
What would you like to learn today?
Browse these popular technologies
Hibernate spring struts Servlets ajax Log4j jQuery Json Core Java Web Services AngularJs
Most Recent Tutorials
Hibernate_Logo Hibernate Recent Posts Spring_Logo Spring Recent Posts Struts_Logo Struts Recent Posts
Useful Links Current & UpComing Tutorials
  Web Services [ SOAP ], JSP
Contact | About Us | Privacy Policy | Advertise With Us

© 2010 - 2017 Java4s - Get It Yourself.
The content is copyrighted to Sivateja Kandula and may not be reproduced on other websites.