PDA

View Full Version : Paging


Nicoláz
03-13-2007, 03:07 PM
I´m using SpringNHibernate Integration and I need to implement Dao Objects to support Queries with Paging.

I know how to implement paging working directly with Nhibernate, but I don´t know how to do it using HibernateSupport and HibernateTemplate.

Could anybody help me?

Thanks!

Nop
03-13-2007, 03:28 PM
Hi Nicol�z.
Try this:

public class Dao
: HibernateDaoSupport,
IDao
{

public IList FindAll <T>(int pageIndex, int pageSize)
{
IQuery query = SessionFactoryUtils.GetSession(HibernateTemplate.S essionFactory, true).CreateQuery(
"from " + typeof(T).Name);

query.SetCacheable(true);
query.SetMaxResults(pageSize);
query.SetFirstResult(pageIndex * pageSize);
IList resultList = query.List();

return resultList;
}
}

Or you can try use ICriteria. It is simpler.
Best regards.

Ismar Slomic
05-13-2007, 01:42 AM
But IQuery is still not integrated with spring. You have to add NHibernate.dll to get access to this interface. Is it possible with help of HQL or some properties in HibernateTemplate to tell startPage and pageCount for returned rows?

Regards Ismar