Consider the example based on Hibernate Criteria Nested Properties
DetachedCriteria detachedCriteria = DetachedCriteria .forClass(Student.class); detachedCriteria.add(Restrictions.eq("name", "Ramesh")); Criteria criteria = detachedCriteria.getExecutableCriteria(session); List list = criteria.list();
An example of Hibernate Criteria Nested Properties is given below
CriteriaNestedProperties.javaADS_TO_REPLACE_1
package net.roseindia.main; import java.util.Iterator; import java.util.List; import net.roseindia.bean.Student; import net.roseindia.util.HibernateUtil; import org.hibernate.Criteria; import org.hibernate.Session; import org.hibernate.criterion.DetachedCriteria; import org.hibernate.criterion.Restrictions; public class CriteriaNestedProperties { public static void main(String[] args) { Session session = HibernateUtil.getSessionFactory().openSession(); DetachedCriteria detachedCriteria = DetachedCriteria .forClass(Student.class); detachedCriteria.add(Restrictions.eq("name", "Ramesh")); Criteria criteria = detachedCriteria.getExecutableCriteria(session); List list = criteria.list(); Iterator iterator = list.iterator(); while (iterator.hasNext()) { Student student = (Student) iterator.next(); System.out.println(student.getName()); } } }
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_.name=? Ramesh Ramesh |
Advertisements
Ads
Ads