In the following code I am trying to get a List of Products which contains all the products in the database:
public List getAllProducts() throws
In Hibernate 5 the session.createCriteria methods are deprecated.
You will need to use a CriteriaBuilder and query from there to get a generic list of Products instead of just List.
Imports
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
Code
CriteriaBuilder builder = session.getCriteriaBuilder();
CriteriaQuery criteria = builder.createQuery(Products.class);
criteria.from(Products.class);
List products = session.createQuery(criteria).getResultList();