HQL (Hibernate Query Language) is Hibernate's own object-oriented query language, syntactically similar to SQL but operating on entity objects and their properties rather than tables and columns directly.
Key Points
HQL queries reference entity class names and field names, not table and column names, making them database-portable.
It understands object-oriented concepts like inheritance and polymorphism — querying a superclass can return subclass instances too.
It supports joins across entity associations using dot notation or explicit join clauses, without needing to know the underlying foreign key columns.
Hibernate translates HQL into database-specific SQL at execution time based on the configured dialect.
JPQL (Java Persistence Query Language) is a closely related, JPA-standardized subset that most HQL knowledge transfers to directly.
Example
The query "from Employee e where e.salary > 50000" returns Employee entity instances directly, letting you write from Employee, not from a table name, and reference salary as a Java field rather than a SQL column.
Query<Employee> query = session.createQuery(
"from Employee e where e.department.name = :deptName", Employee.class);
query.setParameter("deptName", "Engineering");
List<Employee> results = query.list();
Common Mistakes
Writing table and column names in HQL. HQL uses entity and field names, so it must match the Java class, not the database table.
Building HQL with string concatenation, which allows injection. Use named or positional parameters.
Follow-up Questions
What is the difference between HQL and JPQL? JPQL is the JPA standard; HQL is Hibernate's superset of it.
Can HQL do updates and deletes? Yes, with executeUpdate(), but it bypasses the persistence context cache.
Interview Tip
A concise interview answer is
HQL is Hibernate's object-oriented query language — it looks like SQL but operates on entity classes and their properties instead of tables and columns, understands inheritance and associations, and Hibernate compiles it down to database-specific SQL underneath.