一个简单的实例
Session session = sf.getCurrentSession();
//事务开始
session.beginTransaction();
Map<String, String> map = new HashMap<String, String>();
map.put("id", "1");
Criteria c = session.createCriteria(Teacher.class); //等同 from Teacher
c.add(Restrictions.allEq(map));
c.add(Restrictions.lt("id", 2));
c.add(Restrictions.gt("name", "ndxfke"));
c.add(Restrictions.between("id", 1, 5)); //id>=1<=5
c.createCriteria("Class").add(Restrictions.lt("id", 1));
c.list();
session.save(s);
//提交事务
session.getTransaction().commit();
//关闭session
session.close();