File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Object Relational Mapping and the fly likes Difference between HQL and DetachedCriteria Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Difference between HQL and DetachedCriteria" Watch "Difference between HQL and DetachedCriteria" New topic

Difference between HQL and DetachedCriteria

jagrutkumar dalwadi
Ranch Hand

Joined: Mar 26, 2009
Posts: 83

Hi Friends,
I m using Hibernate 3.0. I am little new to hibernate. For getting the data from database, i am using DetachedCriteria and also HQL(Hibernate Query Language). Difference between HQL and DetachedCriteria.

I want to know that in which situation i use DetachedCriteria
and in which situation i use HQL?

and also tell what is the difference between them and drawbacks over each other?

Please try to help my problem.

Hoping for a very good reply.

Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968

HQL allows you to query the database based on the relationships between your objects, in a way that mimics SQL, but in a very object-oriented manner.

A criteria query uses the Hibernate Criteria API to programatically create queries based on your objects, and various classes such as restriction and example.

Here's an HQL Example from my Hibernate Query Language Tutorial:

Here's a Hibernate Criteria Example from my tutorial on using the Hibernate Criteria API:

-Cameron McKenzie
I agree. Here's the link:
subject: Difference between HQL and DetachedCriteria
It's not a secret anymore!