Java, .NET, PHP, PYTHON, ANGULAR, ML, Data Science, Testing, CI Tutorials in Easy Languages.

"Best Software Training, Internship, Project Development center of Indore India, Helpline 780506-3968"

Criteria is used to get complete data from database and return complete object ,It is used to apply condition in object using Restriction class and Criterion Interface.

It is only for Data Selection  not for Data Insertion ,Updation and Deletion.

Code of  Data Selection :-

import java.util.Iterator;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;

import scs.Student;

public class CriteriaExample {

public static void main(String[] args) {
Configuration cfg = new Configuration();
        SessionFactory sf = cfg.buildSessionFactory();
        Session s =sf.openSession();
        Criteria crt = s.createCriteria(Student.class);
       // Criterion crt1 ="fees", 12000);
        Criterion crt1 ="sname", "%m%");
        List lst = crt.list();
        Iterator it = lst.iterator();
        Student stu = (Student);
        System.out.println(stu.getRno() +" "+stu.getSname()+" "+stu.getBranch()+" "+stu.getFees());


Post a Comment

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post