What is Hibernate Query Language(HQL)?


What is Hibernate Query Language(HQL)?

Hibernate Query Language (HQL) is an object-oriented query language. It is similar to SQL, but HQL works with persistent objects and their properties instead of operating on tables and columns.HQL is considered the most powerful query language designed as a minimal object-oriented extension to SQL.

In HQL, we use specific keywords to request data from the database and manipulate it. This process is called querying. Hibernate translates the queries into conventional SQL queries, which act on the database. HQL queries are case insensitive; however, the names of Java classes and properties are case-sensitive. HQL is used to execute queries against the database.

AS Clause

The AS clause is one of the keywords used to make a query. It can be used to assign aliases to the classes in your HQL queries, especially when you have long queries.

For example −

String hql = "FROM Employee AS E";
Query query = session.createQuery(hql);
List results = query.list();

The AS keyword is optional, and you can also specify the alias directly after the class name, as follows −

String hql = "FROM Employee E";
Query query = session.createQuery(hql);
List results = query.list();