wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes Criteria API vs HQL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Criteria API vs HQL" Watch "Criteria API vs HQL" New topic
Author

Criteria API vs HQL

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9521
    
    2

Guys,

What would be the difference between them. Whatever I can do with the Criteria API, I can do with simple HQL. So why would I ever need to use the Criteria API?


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Can you create a syntax error using the Criteria api?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9521
    
    2

Originally posted by Paul Sturrock:
Can you create a syntax error using the Criteria api?


What is a syntax error?
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

An error caused by invalid HQL syntax.
Ajeeth Kumar
Ranch Hand

Joined: Mar 30, 2005
Posts: 56
Paul Sturrock wrote:Can you create a syntax error using the Criteria api?


hey bartender, just pass on the information that he asked for .. dont show off.. i think thats not why you are here in javaranch.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Well Ajeeth, what I was going for was asking a question to lead Jothi to an answer rather than just telling them my opinion (a very old teaching method). But I can see how my response might sound a little curt and, if Jothi didn't think about my question at all, unhelpful.

Internet fora are an environment ripe for misinterpretation, so I will clarify I'm not trying to show off here. But I would remind you that JavaRanch's primary goal is "to help beginners (green horns) learn how to do things themselves" (see this), so where I could have just done as you state I judged it (hopefully) more helpful in the long run to try to get Jothi to think a little about the question they had asked, particularaly as my answer would be an opinion that could be digested in an unqualified way. I suppose I see topics here as a discussion, rather than a simple question/answer.

Now, I don't want you to think I'm piqued here, but I might also point out that there is no obligation on me (or any of the other unpaid volunteers here) to answer any questions posted. Please remember that we ask all participants to BeNice, so I will bear in mind your comments on my response to try to avboid misunderstandings in future and I hope you bear in mind mine next time you post on JavaRanch.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61657
    
  67

Ajeeth Kumar wrote:just pass on the information that he asked for

That is not why we're here at JavaRanch. (With 8 posts, perhaps you're not yet an authority on what JavaRanch is here for?)

Please read NotACodeMill. JavaRanch is a learning site. We're not here just to give out answers, but to teach people how to find them for themselves. Paul's post was a fine way of trying to get Jothi to think through his question and discovers answers on his own.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ajeeth Kumar
Ranch Hand

Joined: Mar 30, 2005
Posts: 56
Paul Sturrock wrote:Well Ajeeth, what I was going for was asking a question to lead Jothi to an answer rather than just telling them my opinion (a very old teaching method). But I can see how my response might sound a little curt and, if Jothi didn't think about my question at all, unhelpful.

Internet fora are an environment ripe for misinterpretation, so I will clarify I'm not trying to show off here. But I would remind you that JavaRanch's primary goal is "to help beginners (green horns) learn how to do things themselves" (see this), so where I could have just done as you state I judged it (hopefully) more helpful in the long run to try to get Jothi to think a little about the question they had asked, particularaly as my answer would be an opinion that could be digested in an unqualified way. I suppose I see topics here as a discussion, rather than a simple question/answer.

Now, I don't want you to think I'm piqued here, but I might also point out that there is no obligation on me (or any of the other unpaid volunteers here) to answer any questions posted. Please remember that we ask all participants to BeNice, so I will bear in mind your comments on my response to try to avboid misunderstandings in future and I hope you bear in mind mine next time you post on JavaRanch.



Agree that javaranch is NotACodeMill, but your posting was rather curt(atleast I thought so) . When people start posting questions here, I assume that they had done some ground work and are now looking for help in the form of quick answers to get them out of some tight situation . I was myself looking at answering some questions on how to effectively use hibernate formulas to retrieve a logical(but fake ) column and how to use the basic DB relationship to imply P-C relationships across multiple levels of hierarchy using Criteria. Hence the outburst.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61657
    
  67

Ajeeth Kumar wrote:Hence the outburst.
Please avoid future outbursts. They help no one.
Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3479

Ajeeth Kumar wrote:
Paul Sturrock wrote:Well Ajeeth, what I was going for was asking a question to lead Jothi to an answer rather than just telling them my opinion (a very old teaching method). But I can see how my response might sound a little curt and, if Jothi didn't think about my question at all, unhelpful.

Internet fora are an environment ripe for misinterpretation, so I will clarify I'm not trying to show off here. But I would remind you that JavaRanch's primary goal is "to help beginners (green horns) learn how to do things themselves" (see this), so where I could have just done as you state I judged it (hopefully) more helpful in the long run to try to get Jothi to think a little about the question they had asked, particularaly as my answer would be an opinion that could be digested in an unqualified way. I suppose I see topics here as a discussion, rather than a simple question/answer.

Now, I don't want you to think I'm piqued here, but I might also point out that there is no obligation on me (or any of the other unpaid volunteers here) to answer any questions posted. Please remember that we ask all participants to BeNice, so I will bear in mind your comments on my response to try to avboid misunderstandings in future and I hope you bear in mind mine next time you post on JavaRanch.



Agree that javaranch is NotACodeMill, but your posting was rather curt(atleast I thought so) . When people start posting questions here, I assume that they had done some ground work and are now looking for help in the form of quick answers to get them out of some tight situation . I was myself looking at answering some questions on how to effectively use hibernate formulas to retrieve a logical(but fake ) column and how to use the basic DB relationship to imply P-C relationships across multiple levels of hierarchy using Criteria. Hence the outburst.

Your assuming is wrong, you can find many people here asking ranchers to do their own home work and asking for code of their own problem, not to mention many don't even bother to google their question first.
Sridhar Santhanakrishnan
Ranch Hand

Joined: Mar 20, 2007
Posts: 317
Ajeeth Kumar wrote:
Paul Sturrock wrote:Well Ajeeth, what I was going for was asking a question to lead Jothi to an answer rather than just telling them my opinion (a very old teaching method). But I can see how my response might sound a little curt and, if Jothi didn't think about my question at all, unhelpful.

Internet fora are an environment ripe for misinterpretation, so I will clarify I'm not trying to show off here. But I would remind you that JavaRanch's primary goal is "to help beginners (green horns) learn how to do things themselves" (see this), so where I could have just done as you state I judged it (hopefully) more helpful in the long run to try to get Jothi to think a little about the question they had asked, particularaly as my answer would be an opinion that could be digested in an unqualified way. I suppose I see topics here as a discussion, rather than a simple question/answer.

Now, I don't want you to think I'm piqued here, but I might also point out that there is no obligation on me (or any of the other unpaid volunteers here) to answer any questions posted. Please remember that we ask all participants to BeNice, so I will bear in mind your comments on my response to try to avboid misunderstandings in future and I hope you bear in mind mine next time you post on JavaRanch.



Agree that javaranch is NotACodeMill, but your posting was rather curt(atleast I thought so) . When people start posting questions here, I assume that they had done some ground work and are now looking for help in the form of quick answers to get them out of some tight situation . I was myself looking at answering some questions on how to effectively use hibernate formulas to retrieve a logical(but fake ) column and how to use the basic DB relationship to imply P-C relationships across multiple levels of hierarchy using Criteria. Hence the outburst.


Your first post wasnt so endearing as well. But back to the OP, I assume you would have googled your queries and found a couple of links that answer your question. Is there something in particular?
Ajeeth Kumar
Ranch Hand

Joined: Mar 30, 2005
Posts: 56
Apologize for the late reply, but I wanted to post this just for the benefit for new learners.

Criteria can be used in situations like where you have a search screen with multiple conditions to search from, but you dont want to have a complex DAO layer code with complex IF / ELSE conditions .

The advantage of Criteria is it adds and implicit AND condition to the query that would be generated by hibernate. The code will also be much easier to understand and maintain or fix.


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Criteria API vs HQL