Criteria Queries vs HQL in Hibernate
- Criteria queries are ideal for dynamic queries. It makes the task of adding ordering, leaving some parts (e.g. restrictions) out depending on some parameter.
- HQL is ideal for static and complex queries coz it it’s much easier to read/understand HQL. It’s a bit more powerful for join queries.
- There is a difference in terms of performance between HQL and criteriaQuery, everytime you fire a query using criteriaQuery, it creates a new alias for the table name which does not reflect in the last queried cache for any DB. This leads to an overhead of compiling the generated SQL, taking more time to execute.