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.