日期:2014-05-17 浏览次数:20768 次
List listGg=(ArrayList)request.getAttribute("listGg");
String hql2="from News order by operateDate desc "; List listGg=dao.find(hql2, 0, 6); request.setAttribute("listGg", listGg);
public List find(String hql, int offset, int size) throws HibernateException { Session session = (Session) HibernateBase.getCurrentSession(); Transaction transaction = null; try { transaction = HibernateBase.getTransaction(session); Query query = session.createQuery(hql); query.setFirstResult(offset); query.setMaxResults(size); List results = query.list(); transaction.commit(); return results; } catch (HibernateException he) { if (transaction != null) { transaction.rollback(); HibernateBase.closeTransaction(); } HibernateBase.closeSession(); throw he; } finally { HibernateBase.closeTransaction(); HibernateBase.closeSession(); } }