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 hibernate.org to learn about it’s framework.
Wah .. Respect to TechieDan!
I think .NET has something similar to this .. called SQL client object .. and I dont think they have a specific name to call it.
Basically, it enhanced the limited SQL statement and fully utilized .NET’s flexibility.
I also know one in SAP where an SQL statement can be made into a loop swt.
Eg. Select * from blabla where blabla=blabla
Do your looping stuff here (swt!!)
End Select
how can i use if else condition inside HQL querry for example i need to retrive names starting with particular letter else i need to retrive all the names..
Thanks in advance
Murali
Aavanor systems
Hello,
you can try something regarding to that by adding a like statement just like how one does in SQL
String query = ” from tableName where name like ‘?%’ ”
I think you can use this query. This was how I test the query.
So far it worked for me. Basically it’s just like a normal SQL.