-->
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 vs. sql
PostPosted: Tue Apr 04, 2006 4:25 pm 
Beginner
Beginner

Joined: Tue Jun 28, 2005 4:33 pm
Posts: 21
I'm curious about the advantages/disavantages of using sql vs. hql with hibernate 3.1. With SQL, we save the learning curve, but what are losing out on that hql does? With hql, I know I can concentrate on my object, but am I losing anything with performance? I'm not looking to be talked into either one, just looking to make an objective list of pros/cons that I can make a decision from.

Thanks.


Top
 Profile  
 
 Post subject: Re: hql vs. sql
PostPosted: Tue Apr 04, 2006 5:05 pm 
Beginner
Beginner

Joined: Fri Mar 17, 2006 7:30 pm
Posts: 32
mjstein6300 wrote:
I'm curious about the advantages/disavantages of using sql vs. hql with hibernate 3.1. With SQL, we save the learning curve, but what are losing out on that hql does? With hql, I know I can concentrate on my object, but am I losing anything with performance? I'm not looking to be talked into either one, just looking to make an objective list of pros/cons that I can make a decision from.

Thanks.


Are you wanting to use SQL through Hibernate or via a raw JDBC connection provided through Hibernate? If the former, Hibernate can still map your objects to the tables and cols, for instance from the docs:

List cats = session.createSQLQuery(
"SELECT {cat.*} FROM CAT {cat} WHERE ROWNUM<10",
"cat",
Cat.class
).list();

The latter does provide a big con in that you are tied to a database implementation. Should a table or column get renamed, then you would have to change every SQL statement that uses it. Also, if you use SQL syntax specific to a db server, changes would have to be made should the database be moved to a new server.

The biggest advantage for HQL to me is not being tied to a particular database. I find it easier to change an XML file than to search through a bunch of Java code. This is also why I don't use annotations as that will tie your POJO to a particular implementation, thereby defeating the whole purpose of a POJO for data.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 04, 2006 5:09 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
I do not think the parsing of hql to sql will result in any noticable performance delay.

I've found there are no negative sides to writing anything in hql. HQL is so similar to sql that there is virtually nothing to learn to get the hang of it. It is less verbose, database independent, and being able to work with objects/attributes makes it very easy to use.

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


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.