File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes When we choose SQL,HQL and Criteria API of hibernate? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "When we choose SQL,HQL and Criteria API of hibernate?" Watch "When we choose SQL,HQL and Criteria API of hibernate?" New topic
Author

When we choose SQL,HQL and Criteria API of hibernate?

Murugesan Pitchandi
Greenhorn

Joined: Nov 19, 2008
Posts: 8

I have java application which is going use hibernate. My doubt is when we choose SQL,HQL and Criteria API of hibernate?
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1646
    
    7

Short answer which gives some general guidelines but not necessarily right for every scenario:

- HQL - use this (preferably named) for most queries. They are easy to read and write.
- Criteria - use this for dynamic queries
- SQL - use this where the other 2 are not a good fit or you want to do something Hibernate either is not designed for, or does not do well. Often times this may be using straight JDBC for some stored procedure work, or batch jobs for example. While Hibernate can do these things it is not always the best choice.


[How To Ask Questions][Read before you PM me]
Murugesan Pitchandi
Greenhorn

Joined: Nov 19, 2008
Posts: 8

Thanks Bill for your reply.

SQL - use this where the other 2 are not a good fit or you want to do something Hibernate either is not designed for, or does not do well. Often times this may be using straight JDBC for some stored procedure work, or batch jobs for example. While Hibernate can do these things it is not always the best choice.

You mean to say, in case your application having stored procedure/batch process then HQL and Criteria API of hibernate work and it will support by SQL only. Please correct me if i am wrong.

Thanks and Regards,
Murugesab
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: When we choose SQL,HQL and Criteria API of hibernate?
 
Similar Threads
Different between Criterial and Query
Online test application
How do I create Hibernate criteria when using a many to one mapping
Hibernate 3 not able to recognize the "ON" word in sql
Named Queries in hibernate