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 Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: