Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

347
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!