What is the HQL in hibernate ? Explain the use of HQL.
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.