HQL stand for Hibernate Query Language. Hibernate Query Language (HQL) is an object-oriented query language, similar to SQL, but instead of operating on tables and columns, HQL works with persistent objects and their properties. HQL queries are translated by Hibernate into conventional SQL queries.
The HQL query is created with syntax:
1 |
session.createQuery |
Example:-
1 2 3 |
String hql = "FROM Employees"; Query query = session.createQuery(hql); List results = query.list(); |
The main advantage of HQL over SQL is:
- You don’t need to learn SQL
- Database independent
- Simple to write a query