Difference between HQL and Criteria Query in Hibernate

Hibernate » On Jul 14, 2011 By Sivateja

Let us see the main differences between HQL and Criteria Query

  • HQL is to perform both select and non-select operations on the data,  but Criteria is only for selecting the data, we cannot perform non-select operations using criteria
  • HQL is suitable for executing Static Queries, where as Criteria is suitable for executing Dynamic Queries
  • HQL doesn’t support pagination concept, but we can achieve pagination with Criteria
  • Criteria used to take more time to execute then HQL
  • With Criteria we are safe with SQL Injection because of its dynamic query generation but in HQL as your queries are either fixed or parametrized, there is no safe from SQL Injection.


Java/J2EE Developer & Web Designer, founder of Java4s.com. Sign-up for the email newsletter for your daily dose of Java tutorials.
Email: sivateja@java4s.com


15 Responses to “Difference between HQL and Criteria Query in Hibernate”
  1. ramu says:

    hai sir,
    thanks a lot for ur lovly heart this all concepts very usefull

  2. java4s.com says:

    @ramu :-) you bet, thanks for your feedback

  3. Ram says:

    I wont agree with pagination concept given by you
    please refer below
    Hibernate APIs provide few methods to set the pagination citerias in the query. We can use bothe normal Query and Criteria API. Look into the following code for how to create pagination using the Query object:

    Query query = session.createQuery(“from Studenet s”);
    For Criteria :

    Criteria criteria = session.createCriteria(Student.class);
    List result = criteria.list();

  4. Steven says:

    Thanks a ton for the valuable information.

  5. Mahi says:


    Can u please explain select and non-select operations with example in both hql and criteria queries.i am nt clear with the above statement.


  6. puglist says:

    “HQL is suitable for executing Static Queries”. HQL is also suitable for executing dynamic

    queries by using Query.setParameter()mthod. In that method we can able to pass the values

    at run time.so how we can able to say HQL is suitable to execute static query?.

  7. rizwana says:

    how can i use joins in criteria concepts?

  8. Thanks alot SivaTeja…
    this is very good meterial for hibernate.

  9. ashok says:

    easily understand….

  10. Hi,
    In your last point you mentioned about sql injection.
    could you please explore it with proper example.

  11. Hari says:

    we can write dynamic quries using hql, but u are telling HQL is suitable for executing Static Queries, where as Criteria is suitable for executing Dynamic Queries

  12. karthick says:

    completely analysed,,,,,great thanx to you….

  13. vanaja says:

    I have one doubt, Why HQL does not support pagination?

  14. Romi says:

    Good article.

  15. Ganesh selvam says:

    super sir…..thanks a lot.


By posting your answer, you agree to our comments policy.
© 2010 - 2016
Java4s - Get It Yourself.
The content & design is copyrighted to Sivateja Kandula, it may not be reproduced on other websites.
What would you like to learn today?
Browse these popular technologies
Hibernate spring struts Servlets ajax Log4j jQuery Json Core Java Web Services AngularJs

Most Recent Tutorials
Hibernate Recent Posts
Spring Recent Posts
Struts Recent Posts
Recomandded Links
Current & UpComing Tutorials
  Web Services [ SOAP ], JSP
Facebook_Java4s  Twitter_Java4s  GooglePlus_Java4s  Youtube_Java4s 
Contact | About Us | Privacy Policy | Advertise With Us

© 2010 - 2016 Java4s - Get It Yourself.
The content is copyrighted to Sivateja Kandula and may not be reproduced on other websites.