public Service getServiceData(){
return (Service)ServiceDaoImpl.getSession().get(Service.class, new Integer(1));
}
The get method is getting one. I want to get all data for the jsp page.
With the Hibernate 5 the createCriteria is deprecated use something like this
private static <T> List<T> loadAllData(Class<T> type, Session session) {
CriteriaBuilder builder = session.getCriteriaBuilder();
CriteriaQuery<T> criteria = builder.createQuery(type);
criteria.from(type);
List<T> data = session.createQuery(criteria).getResultList();
return data;
}
usage
Session session = HibernateUtils.getSession();
List<User> users = loadAllData(User.class, session);
Try below piece of code and replace Entity with your Entity class
@SuppressWarnings("unchecked")
public List<Entity> getAlldata(){
try
{
return sessionFactory.getCurrentSession().createCriteria(Entity.class).list();
} catch (Exception e) {
return new ArrayList<>();
}
}
Try as following to get all rows from table
@SuppressWarnings("unchecked")
public List<Service> Service getServiceData() {
return ServiceDaoImpl.getSession().createQuery("from Service").list();
}