Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

445
Vistas
How to get all data in the table with hibernate?
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.

about 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

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);
about 4 years ago · Santiago Trujillo Denunciar

0

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<>();
    }
}
about 4 years ago · Santiago Trujillo Denunciar

0

Try as following to get all rows from table

@SuppressWarnings("unchecked")
    public List<Service> Service getServiceData() {

         return ServiceDaoImpl.getSession().createQuery("from Service").list(); 
    }
about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda