离线查询对象的思想,简化代码,不至于每一种插叙都要建立不同的查询路径
离线查询代码
//Service/web层 DetachedCriteria dc = DetachedCriteria.forClass(Customer.class); dc.add(Restrictions.idEq(6l));//拼装条件(全部与普通Criteria一致) //Dao层 Session session = HibernateUtils.openSession(); Transaction tx = session.beginTransaction(); //获得非离线Criteria Criteria c = dc.getExecutableCriteria(session); List list = c.list();