Hibernate Query Language (HQL)
AIM:
We use from clause in hibernate to select records from database
Syntax
From Employee employee;
Procedure:
Step 1:
Create Hibernate Reverse Engineering wizard
Step 2:
Create HibernateUtil.java
Step 3:
Create POJO class and mapping files
Step 4:
Create jsp file named as FromClause
Include following coding into FromClause
< %@page import="org.hibernate.SessionFactory,org.hibernate.Session" % >
< %@page import="org.hibernate.cfg.Configuration,org.hibernate.*" % >
< %@page import="Hiber.Employee" % >
< %@page import="java.util.*" % >
< %@page contentType="text/html" pageEncoding="UTF-8"% >
< !DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
http://www.w3.org/TR/html4/loose.dtd >
< html >
< head >
< title > JSP Page < /title >
< /head >
< body >
< %
try
{
SessionFactory sessionFactory=new Configuration().configure().buildSessionFactory();
Session s=sessionFactory.openSession();
String sql="from Employee employee";
Query query=s.createQuery(sql);
Iterator it=query.iterate();
% >
< table border="5" >
< caption > < b > Example For Hibernate- From Clause < /b > < /caption >
< tr > < th > EmployeeName < /th > < th > EmployeeID < /th > < /tr >
< %
while(it.hasNext())
{
Employee e=(Employee)it.next();
% >
< tr >
< td > < %= e.getEmpname() % > < /td >
< td > < %= e.getEmpno() % > < /td >
< /tr >
< %
}
% >
< /table >
< %
}
catch(Exception e)
{
out.println(e);
}
% >
< /body >
< /html >
Step 5:
Run the FromClause.
Right click on FromClause.jsp and select Run
Step 6:
Structure Of the Hibernate-From Clause
I have no words for this great post such a awe-some information i got gathered. Thanks to Author.
ReplyDelete