Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

453
Visualizações
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.

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

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);
over 4 years ago · Santiago Trujillo Relatório

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<>();
    }
}
over 4 years ago · Santiago Trujillo Relatório

0

Try as following to get all rows from table

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

         return ServiceDaoImpl.getSession().createQuery("from Service").list(); 
    }
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda