Hibernate

adplus-dvertising
Syntax Of HQL Queries
Previous Home Next

To fetch the all the object of a type

from classname as Alias

To fetch all the emp object

Query q=Session.createQuery("From Emp e")

To fetch only Those object to class which satisfy given condition

from classname as Alias where condition

To fetch all those employee who earn more 75000/month

from Emp e where e.salary>75000

To fetch name of all manager

select e.name from Emp e where e.job="manager"

Note:-

HQL queries supports named as well as positioned parameters
First Approach:-(positioned parameter):-
Query q=session.createQuery("select e.name from Emp e e.job=?");
q.setString(1,job);
// value of positioned parameter is set.

Second Approach(Named parameter):-
Query q=session.createQuery("from Emp e where e.salary>:salary");
q.setInt("salary",s);
Previous Home Next