-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: HQL ? Criteria ?
PostPosted: Mon Dec 05, 2005 6:58 pm 
Newbie

Joined: Mon Dec 05, 2005 6:52 pm
Posts: 4
Location: Atlanta
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:3.1

HQL ? Criteria ?

HQL Named Queries ? Criteria ? which one is better. Can someone please compare and let me know how these two things works behind the scenes ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 05, 2005 8:07 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
They are two different APIs where power is similar (in H3.x) so it really boils down to which you feel most comfortable with.
I have a preference toward HQL as I am use to using it (and SQL etc) but Criteria really does have features that make requirements such as adhock searches very easy to do. It also has the added benefit of being largely compile time checked which reduces possible errors in the query being generated. As far as the backend goes, they both, in the end, generate SQL strings for the JDBC driver to process.

I suggest you play with both and find which API you are the most comfortable with. Having said that you can use both, where appropriate, through your application.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 05, 2005 10:17 pm 
Beginner
Beginner

Joined: Tue Jun 07, 2005 11:36 pm
Posts: 22
My $.02:

1) HQL is very nice and pretty compact. Definately set up a small tester app where you can quickly paste in HQL strings you are trying out to make sure they are syntactically and loggically correct. Once you know the string is correct, make it a named query so that it loads and compiles at app startup. This way, if you make any tweaks to it and forget to check them, you'll catch syntactic errors at app startup (or test framework startup) rather than having to run through and execute all the steps to hit the query before seeing any errors.

2) HQL is perfect if you have a piece of your app which needs to load in a changing set of user queries without touching code. For example, I have written a stats package for our app where the admin can add new HQL queries to an XML config file to generate statistics about how the app is being used. The results then feed into a series of jfreechart/cewolf pages to be displayed graphically, all without touching the core java code.

2) To me, the most interesting thing about the Criteria API is the query by example (QBE) piece. However, I can rarely use that because I depend on relations to other entities in my queries so much. If this code is incorporated:

http://opensource2.atlassian.com/projec ... se/HHH-408

or even a subset of it, I think Criteria will be much more powerful.

_________________
Useful? Hit me with a point! Completely off base? Ya, well, what do you expect from a newbie...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.