Session session = HibernateUtil. getSessionFactory (). openSession ();
Criteria criteria = session. createCriteria (People. class );
// List list = criteria. list (); // select * from people
// Criteria. add (Restrictions. gt ("id", 2); // select * from people where id> 2;
// Criteria. add (Restrictions. between ("id", 1, 5); // select * from people where id between 1 and 5;
// Criteria. add (Restrictions. isNull ("password"); // select * from people where password is noll;
// Criteria. add (Restrictions. eq ("name", "cf"); // select * from people where name = 'cf ';
// Criteria. add (Restrictions. like ("name", "_ f"); // select * from people where name like '_ F ';
// Criteria. add (Restrictions. lt ("id", 6); // select * from people where id <6;
// Criteria. add (Restrictions. and (Restrictions. ge ("id", 2), Restrictions. le ("id", 3 )));
// Select * from people where id> = 2 and id <= 3;
// Criteria. add (Restrictions. or (Restrictions. eq ("name", "cf"), Restrictions. gt ("id", 2 )));
// Select * from people where id> 2 or name = 'cf ';
// Criteria. add (Restrictions. in ("id", new Integer [] {1, 2, 3 }));
// Select * from people where ID in (1, 2, 3 );
// Criteria. addorder (order. ASC ("name "));
// Select * from people order by name ASC;
// Criteria. setfirstresult (1 );
// Criteria. setmaxresults (2 );
// Select * from people limit 1, 2;
// Criteria. setprojection (projections. Count ("ID "));
// Select count (ID) from people;
// Criteria. setprojection (projections. AVG ("ID "));
// Select AVG (ID) from people;
// Criteria. setprojection (projections. groupproperty ("name "));
// Select name from people group by name;
// Criteria. setprojection (projections. rowcount ());
// Select count (*) from people;
// Projectionlist = Projections. projectionlist ();
// Projectionlist. Add (projections. groupproperty ("name "));
// Projectionlist. Add (projections. rowcount ());
// Criteria. setprojection (projectionlist );
// Select name, count (*) from people group by name;
List list = criteria. List ();