0

I'm working on a webapp that uses Spring Boot and Hibernate. In a certain page I have to load a list with over 800 elements and each of these require another query to be made in order to populate a field.

Like this:

    @Path(value = {"search"})
    public void search() {
        List<Item> items= new ArrayList<Item>();
        items= itemsDAO.find();

        for (Item item : items) {
            //Another query being made here, to populate the property
            item.setProperty(calculateProperty(item.getId());
        }

        result.use(Results.json()).withoutRoot().from(items)
                .serialize();
    }

So this is how its being done for now. And it is VERY slow. Because it has to iterate over 800 items and use the calculateProperty method, which makes other HQL queries in order to fill the property.

What I'm asking is. How can I do this is a less time-expensive way? Is there a way, without saving this particular data in the DB to make Hibernate load this data?

Any tips and/or similar solutions are very welcome.

WilsonPena
  • 1,451
  • 2
  • 18
  • 37

0 Answers0