Criteria Queries vs HQL in Hibernate


  1. 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.
  2. 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.
  3. 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.

Leave a comment