Hibernate criteria sum.
Posted on: April 11, 2011 at 12:00 AM
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);


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);
		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.: