Hibernate-Entity Query:
Introduction:
Example:
Procedure:
Create Hibernate Project as HibernateNativepro. |
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 NativeSelect.jsp
Include following coding into the EntityPro.jsp
< %@page import="Hiber.Student"% >
< %@page import="org.hibernate.*" % >
< %@page import="org.hibernate.cfg.*" % >
< %@page import="org.hibernate.criterion.*" % >
< %@page import="java.util.*" % >
< html >
< head >
< title > Entity Example < /title >
< /head >
< body >
< %
try
{
SessionFactory sessionFactory=new Configuration().configure().buildSessionFactory();
Session s=sessionFactory.openSession();
List list=s.createSQLQuery("select * from Student student").addEntity(Student.class).list();
Iterator it=list.iterator();
while(it.hasNext())
{
Student s2=(Student)it.next();
out.println(s2.getStuname());
}
}
catch(Exception e)
{
out.println(e);
}
% >
< /body >
< /html >
Output:
No comments:
Post a Comment