Hibernate Project- SUM
Introduction:
We are going to understand how to use sum in Projection.
Problem:
To get sum of all Tamil marks.
Solution:
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 nameds as ProjectionSum.jsp
Include following coding into ProjectionSum.jsp
< %@page import="Hiber.Student"% >
< %@page import="org.hibernate.*" % >
< %@page import="org.hibernate.cfg.*" % >
< %@page import="org.hibernate.criterion.*" % >
< %@page import="org.hibernate.Criteria.*" % >
< %@page import="java.util.*" % >
< html >
< head >
< title > Hipernate Projection SUM Example < /title >
< /head >
< body >
< %
try
{
SessionFactory sessionFactory=new Configuration().configure().buildSessionFactory();
Session se=sessionFactory.openSession();
Criteria crit=se.createCriteria(Student.class);
ProjectionList p=Projections.projectionList();
p.add(Projections.sum("tamil"));
crit.setProjection(p);
List list=crit.list();
Iterator it=list.iterator();
while(it.hasNext())
{
Object obj=(Object)it.next();
out.println(obj);
}
}
catch(Exception e)
{
out.println(e);
}
% >
< /body >
< /html >
Output:
No comments:
Post a Comment