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.  [ 2 posts ] 
Author Message
 Post subject: Is HQL faster and more efficient then just using objects??
PostPosted: Fri Jun 13, 2008 9:50 am 
Newbie

Joined: Fri Jun 13, 2008 9:22 am
Posts: 1
I am new to Nhibernate and I am trying to fully understand why HQL is used if Nhibernate already gives you objects that represent your DB.

I would just like to know if using HQL is faster than using the objects that you get from Nhibernate?

For example:
Is this HQL query (exscuse any syntax errors remember I am new)

Code:
session.CreateQuery("select cout(*) from Foo as foo where foo.Bar as fooBar where fooBar.id= 1 and Bar.something = 'chicken'");



Faster than this

Code:
Foo myFoo = (Foo)session.Load(typeof(Foo),1);
foreach(Bar myBar in myFoo.Bar)
{
    if(myBar.something == "chicken")
    {
       counter++;
     }
}


I understand that for this example using HQL would make more sense because its a lot less work. But my question is which is faster and more efficient? I would also like to know where does the HQL query take place? Is the work done on the DB server or is it done one the application machine?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 13, 2008 1:57 pm 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
The answer to your last question explains the rest: HQL is translated (via Dialect) to DB-specific SQL, and run on the DB. Therefore, for data-centric queries it is almost always faster than "querying" the objects that NH returns.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.