Home Hibernate Examples Criteria Hibernate criteria sum.

Ask Questions?

View Latest Questions


 
 

Hibernate criteria sum.
Posted on: April 11, 2011 at 12:00 AM
Advertisement
Hibernate criteria sum.

Hibernate criteria  sum.

Here, we will introduce you to about the sum() function . It returns the sum of total value of column.

Syntax :

Criteria criteria=session.createCriteria(Pojo.class);
criteria.setProjection(Projections.sum(propertyName));

LazyLoading.java

package net.roseindia.action;

import java.util.List;
import net.roseindia.bean.StudentBean;
import net.roseindia.util.HibernateUtil;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Projections;

public class CriteiaSort {
	public static void main(String[] args) {
		Session session = HibernateUtil.getSessionFactory().openSession();
		Criteria criteria = session.createCriteria(StudentBean.class);
		criteria.setProjection(Projections.sum("fee"));
		List totalFee = criteria.list();
		System.out.println("Total of fee columm : " + totalFee);
	}
}
When you run this application it will display message as shown below:
Hibernate: select sum(this_.fee) as y0_ from studentinfo this_
Total of fee columm : [5000]

Download Complete Source Code

Related Tags for Hibernate criteria sum.:


DMCA.com