Sample HQL Query

For those Java like programmers, they will be using pure SQL statements to get the whole of a table by typing the typical SQL query statement.

String SQL = "select * from tablename where condition = ?";

From then onwards it can be passed to a POJO to be declared but everything has to be done one by one where each POJO object is set one by one. I have also written a simple complex SQL call in Java previously here. Now what if you had a hibernate mode setup, it’ll be just one time setup and you’ll get it redirect to the POJO it was meant to be.

Though this time, I’ll be talking about how HQL Query is somewhat similar to the above SQL query.

String SQL = " from tableName where condition = ?";
HibernateTemplate hibernate =
new HibernateTemplate(this.getSessionFactory());
List list = hibernate.find(SQL,"condition");

Now in just 2 lines I can call a SQL query in a simple HQL Query. Now how simple is Hibernate, if you would like to know more about hibernate, visit to learn about it’s framework.


  1. Lasker January 21, 2009
  2. Murali February 19, 2009
    • techieDan February 25, 2009

Leave a Reply