What is the difference between HQL and Criteria in Hibernate?

UPDATED: 01 November 2017
HQL (Hibernate Query Language)

  • HQL can be used to perform SELECT, INSERT, UPDATE, DELETE.
  • SQL injection possible if not used parameterized query.
  • SELECT STATEMENT: You've to manually write the long queries, take care of where and other syntax.

Criteria

  • Criteria can be used to perform only SELECT.
  • SQL injection is not possible with Criteria because hibernate will take care of it while generating SQL query.
  • SELECT STATEMENT: Criteria interface comes with handy methods and take care of where and other syntax.

These are the basic difference between HQL (Hibernate Query Language) and Criteria. Do comment if other important difference is there.

Check out the stackoverflow thread for performance of Hibernate Criteria vs HQL: which is faster?

0 comments :