Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



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

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


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


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


Advertisement
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 Tutorials/Questions & Answers:
Advertisements
 

 

 

DMCA.com