Hibernate Query Language (HQL) Examples

HQL stands for Hibernate Query Language, and is the data query language that comes with Hibernate. Hibernate is a Java-based library for accessing relational data.The main difference between is HQL uses class name instead of table name, and property names instead of column name.


HQL is very similar to SQL, but has two powerful benefits:
  • HQL provides one language for accessing different SQL databases, each with its own slightly different flavor of SQL; and
  • HQL has object oriented extensions which can be very powerful.
HQL - From Clause :

String SQL_QUERY ="from Employee";
Query query = session.createQuery(SQL_QUERY);
List<employee> emplist = query.list();

HQL - Where Clause :

Query query = session.createQuery("from Employee 
        where empno = :num");
query.setParameter("num", "7277");
List<Employee> list = query.list();

HQL Update Query :


Query query = session.createQuery("update Employee set empName= :empname" +
        " where empNo = :num");
query.setParameter("empname", "Jaames");
query.setParameter("num", "123");
int result = query.executeUpdate();


Enter your email address to get our daily JOBS & INTERVIEW FAQ's Straight to your Inbox.

Make sure to activate your subscription by clicking on the activation link sent to your email