Hibernate Criteria Unique List
Posted on: April 13, 2011 at 12:00 AM
In this tutorial you will learn about hibernate criteria unique list

Hibernate Criteria Unique List

An example of hibernate criteria unique list is given below, which returns the unique value in list from a table

CriteriaUniqueList.java

package net.roseindia.main;

import net.roseindia.bean.Student;
import net.roseindia.util.HibernateUtil;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;

public class CriteriaUniqueList {
	public static void main(String[] args) {
		Session session = HibernateUtil.getSessionFactory().openSession();
		Criteria criteria = session.createCriteria(Student.class);
		criteria.add(Restrictions.eq("rollNo", 1));
		Student student = (Student) criteria.uniqueResult();
		System.out.println(student.getName());
	}
}

When you run this application it will display message as shown below:

Hibernate: select this_.roll_no as roll1_0_0_, this_.name as name0_0_, this_.course as course0_0_, this_.address as address0_0_ from student this_ where this_.roll_no=?
Ramesh

Download Complete Source CodeADS_TO_REPLACE_1

Related Tags for Hibernate Criteria Unique List:

Advertisements

Ads

Ads

 
Advertisement null

Ads