Hibernate

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

Tolal:0 Click:

Show All Comments

Did not find what you were looking for leave your name and message. We will revert within 24 hours
Name:
eMail:
Comment / Feedback: