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

Hibernate criteria setFirstResult.

In this tutorial, you will see the use of seFirstResult() method of criteria class. The setFirstResult() tell hibernate from which row the data should be read.

Syntax :

Criteria criteria=session.createCriteria(Pojo.class);
criteria.setFirstResult(int arg);


package net.roseindia.action;

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

public class CriteiaSort {
	public static void main(String[] args) {
		Session session = HibernateUtil.getSessionFactory().openSession();

		Criteria criteria = session.createCriteria(StudentBean.class);
		List list = criteria.list();
		Iterator studentIter = list.iterator();
		System.out.println("   Roll No      Name      Address   ");
		while (studentIter.hasNext()) {
			StudentBean student = (StudentBean) studentIter.next();
			System.out.print("\t" + student.getRoll() + "\t");
			System.out.print(student.getName() + "\t");
			System.out.print(student.getAddress() + "\n");
When you run this application it will display message as shown below:
Hibernate: select this_.id as id0_0_, this_.name as name0_0_, this_.class as class0_0_, this_.address as address0_0_, this_.email as email0_0_, this_.joindate as joindate0_0_ from studentinfo this_
Roll No Name Address
2 gyan Bareilly
3 vrishti Kanpur
4 parineeta GKP
5 Rohit Barabanki

Download Complete Source Code

Related Tags for Hibernate criteria setFirstResult.:



Advertisement null