Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Hibernate Query Langugae (HQL)

Hibernate Query Language:

  • HQL is one of the feature of Hibernate.
  • HQL is same like SQL but here it uses class name as table name and variables as columns.
  • HQL is Database independent query language.
  • An object oriented form of SQL is called HQL
  • HQL syntax is very much similar to SQL syntax.  Hibernate Query Language queries are formed by using Entities and their properties, where as SQL quires are formed by using Tables and their columns.
  • HQL Queries are fully object oriented..
  • HQL Queries are case sensitive.

Advantages of HQL:

  • Database Independent
  • HQL Queries supports inheritance and polymorphism
  • Easy to learn. 

Query Interface:

  • Query interface used to Represent HQL query in the form of query object.
  • The object of  query will be created by calling createQuery(hql query) method of session.

    1.  Session hsession = sf.openSession();
    2. Query query = hsession.createQuery(hql query);

    • Send the query object to hibernate software by calling the list method.
    • Hibernate returns an ArrayList object render the ArrayList object and display the output to client.

    1. List l = query.list();
    2. ArrayList emplist = (ArrayList)l;

    • Query is an interface which is available as port of org.hibernate package. We can not create the object to query interface. We can create a reference variable and it holds implementation class object.

     Methods of Query Interface:

    This post first appeared on Java Tutorial - InstanceOfJava, please read the originial post: here

    Share the post

    Hibernate Query Langugae (HQL)


    Subscribe to Java Tutorial - Instanceofjava

    Get updates delivered right to your inbox!

    Thank you for your subscription