How to get List of records in Hibernate
// List all recordsthis is body.
public List<User> list(){
return sessionFactory.getCurrentSession()
.createCriteria(User.class).list(); // List all records
}
// List records based on MAX
public List<User> list(Integer max){
return sessionFactory.getCurrentSession().createCriteria(User.class)
.setMaxResults(max).list();
}
// List records with MAX records and OFFSET
public List<User> list(Integer max, Integer offset){
return sessionFactory.getCurrentSession().createCriteria(User.class)
.setMaxResults(max)
.setFirstResult(offset)
.list();
}
// List records with MAX records and OFFSET and ORDER by id field of User class
public List<User> list(Integer max, Integer offset){
return sessionFactory.getCurrentSession().createCriteria(User.class)
.setMaxResults(max)
.setFirstResult(offset)
.addOrder(Order.asc("id"))
.list();
}
Comments
Post a Comment