Home Answers Viewqa Hibernate-Interview-Questions HQL in hibernate ? Explain the use of HQL.

 
 


ratna rathor
HQL in hibernate ? Explain the use of HQL.
1 Answer(s)      11 months ago
Posted in : Hibernate Interview Questions

What is the HQL in hibernate ? Explain the use of HQL.

View Answers

June 11, 2012 at 7:03 PM


HQL stands for Hibernate Query Language, provided by Hibernate. It is minimal object oriented, similar to SQL. It works like a bridge between database and application. Here is one example of case insensitive search.

package net.roseindia.main;

import java.util.*;
import net.roseindia.table.Employee;
import net.roseindia.util.ConnectionUtil;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

public class CaseInsensitiveHQL {
    public static void main(String[] args) {
        SessionFactory sessionFactory = ConnectionUtil.getSessionFactory();
        Session session = sessionFactory.openSession();
        String hql="SELECT emp from Employee emp WHERE emp.name='Ron'";
        Query query=session.createQuery(hql);
        Iterator it=query.iterate();
        while ( it.hasNext()) {
            Employee employee = (Employee) it.next();
            System.out.println(employee.getName());
            System.out.println("Salary : "+employee.getSalary());
        }
        session.close();
    }
}

Description: Here we are printing name and salary of employee whose name matches to ?Ron? .HQL looks like SQL.Its query is case-insensitive expect we are using the java class and properties.

For more in HQL Click here.









Related Pages:

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.