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();