Newsletter |
Part 2 Hibernate Query Language, Executing HQL Commands
Hibernate » on Jul 8, 2011 { 5 Comments } By Sivateja
Let us see, how to execute HQL commands..
Procedure To Execute HQL Command:
- If we want to execute execute an HQL query on a database, we need to create a query object
- ” Query ” is an interface given in org.hibernate package
- In order to get query object, we need to call createQuery() method in the session Interface
- Query is an interface, QueryImpl is the implemented class
- we need to call list method for executing an HQL command on database, it returns java.util.List
- we need to use java.util.Iterator for iterating the List collection
Syntax:
Query qry = session.createQuery("--- HQL command ---"); List l = qry.list(); Iterator it = l.iterator(); while(it.hasNext()) { Object o = it.next(); Product p = (Product)o; ----- ------- --------- }
Notes:
- line 1: Getting the Query object
- line 2: Executing the object content (which is HQL command)
- line 3: Iterating, then while loop and type cast into our class type that’s it
Next Session HQL part 3
You Might Also Like
::. About the Author .:: | ||
Comments
5 Responses to “Part 2 Hibernate Query Language, Executing HQL Commands”
Full marks to you ..awsome tutorials and wonderful concepts..but please correct the definition of composite key because it can confuse a fresher.
Cheers!!! Neeraj 🙂
Mr Siva and Team,
This is Excellent tutorials…..It`s Easy for learning.
It would be much appreciated if included annotation examples also for all topics.
As most of the projects using annotations only.
Thanks…. 🙂
Swamy Nadhan G
This is Excellent Tutorials Super Sir
Mr Siva and Team,
It would be much better if included examples with jsp
Excellent Tutorial sir….keep it up and keep it updated with latest versions…very good work. 🙂