示例如下 :
/**
* 查询一条记录
*/
public void testQueryOnlyOnResult(){
Session session = null;
Transaction tx = null;
session = HibernateUtils.getCurrentSession();
tx = session.beginTransaction();
Criteria criteria = session.createCriteria(Guestbook.class);
Criterion criterion1 = Restrictions.like("name", "刘%");
Criterion criterion2 = Restrictions.between("id", new Integer(1), new Integer(10));
criteria.add(criterion1);
criteria.add(criterion2);
criteria.setMaxResults(1);
Guestbook g = (Guestbook)criteria.uniqueResult();
tx.commit();
session.close();
System.out.println(g.toString());
}