Newsletter

Part 2 Hibernate Query Language, Executing HQL Commands

Hibernate » on Jul 8, 2011 { 5 Comments } By Sivateja

Let us see, how to execute HQL commands..

Procedure To Execute HQL Command:

  • If we want to execute execute an HQL query on a database, we need to create a query object
  • Query ” is an interface given in org.hibernate package
  • In order to get query object, we need to call createQuery() method in the session Interface
  • Query is an interface, QueryImpl is the implemented class
  • we need to call list method for executing an HQL command on database, it returns java.util.List
  • we need to use java.util.Iterator for iterating the List collection

Syntax:

Query qry = session.createQuery("--- HQL command ---");
List l = qry.list();
Iterator it = l.iterator();
while(it.hasNext())
{
  Object o = it.next();
  Product p = (Product)o;
  ----- ------- ---------
}

Notes:

  • line 1: Getting the Query object
  • line 2: Executing the object content (which is HQL command)
  • line 3: Iterating, then while loop and type cast into our class type that’s it

Next Session HQL part 3

​​

You Might Also Like

  ::. About the Author .::

Java4s_Author
Sivateja Kandula - Java/J2EE Full Stack Developer
Founder of Java4s - Get It Yourself, A popular Java/J2EE Programming Blog, Love Java and UI frameworks.
You can sign-up for the Email Newsletter for your daily dose of Java tutorials.

Comments

5 Responses to “Part 2 Hibernate Query Language, Executing HQL Commands”
  1. Neeraj says:

    Full marks to you ..awsome tutorials and wonderful concepts..but please correct the definition of composite key because it can confuse a fresher.

    Cheers!!! Neeraj 🙂

  2. Swamy says:

    Mr Siva and Team,

    This is Excellent tutorials…..It`s Easy for learning.
    It would be much appreciated if included annotation examples also for all topics.
    As most of the projects using annotations only.

    Thanks…. 🙂
    Swamy Nadhan G

  3. vamsi says:

    This is Excellent Tutorials Super Sir

  4. siddu says:

    Mr Siva and Team,

    It would be much better if included examples with jsp

  5. gaurav pathak says:

    Excellent Tutorial sir….keep it up and keep it updated with latest versions…very good work. 🙂

Name*
Mail*
Website



By posting your answer, you agree to our comments policy.
Most Recent Posts from Top Categories
Spring Boot Hibernate Spring
Contact | About Us | Privacy Policy | Advertise With Us

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