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 Difference between HQL and DetachedCriteria Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Difference between HQL and DetachedCriteria" Watch "Difference between HQL and DetachedCriteria" New topic
Author

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.

Regards,
Jagrut
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Difference between HQL and DetachedCriteria
 
Similar Threads
Hibernate with DAO?
How do I create Hibernate criteria when using a many to one mapping
Hibernate Criteria object - how to... ?
Hibernate Search in Action: What do you mean by Search exactly?
Hibernate many-to-many ...with DetachedCriteria/ Criteria