I am implementing DAO in Spring-5, Maven Project with Hibernate 5, for getting list with offset and maxcount with the help of
sessionFactory.getCurrentSession().createCriteria()
but its now deprecated and i want to implement
I want these three function to be in new method for what createCiteria()
replaced
@Override
public List<Department> list(Integer offset, Integer maxResults) {
return sessionFactory.getCurrentSession()
.createCriteria(Department.class)
.setFirstResult(offset!=null?offset:0)
.setMaxResults(maxResults!=null?maxResults:10)
.addOrder(Order.asc("department_name"))
.list();
}
AND
@Override
public Long count() {
return (Long)session.openSession()
.createCriteria(Department.class)
.setProjection(Projections.rowCount())
.uniqueResult();
}
AND With Restrictions.eq()
@Override
public List<Department> getAllDepartmentsByDepartmentTypeId(int department_type_id) {
return session.getCurrentSession()
.createCriteria(Department.class)
.addOrder(Order.asc("department_name"))
.add(Restrictions.eq("department_type_id", department_type_id))
.list();
}
I want these three method to be implemented so that i can use instead of deprecated createCriteria() method