Grid (LazyLoad is slow) Vaadin 14

Hello, please help


DATA SIZE : ~21000 rows

public static <T> List<T>findAllWithRigts(int offset, int limit, Class<T> tClass) {
       String rightsQuery =,tClass);
       Session session = HibernateHikariUtil.getSession();
       String sql = "From "+tClass.getSimpleName() +"  WHERE  "+rightsQuery+" ORDER BY dateCreate DESC";
       Query query = session.createQuery(sql)

       return query.getResultList();
public static<T> int getCount(Class<T> tClass) {

         String rightsQuery =,tClass);
         Long count = (Long)  HibernateHikariUtil.getSession().createQuery("SELECT count(*) FROM "+tClass.getSimpleName()+" WHERE "+rightsQuery).uniqueResult();
           Integer c = toIntExact( count);
           return c;

DAO.getCount(getCurrentClass()) and DAO.findAllWithRigts(offset, limit, getCurrentClass()) : its work fast ~200ms;

But Grid element init: **~ 8sec **

My code:

int totalCount = DAO.getCount(getCurrentClass());
DataProvider<Object, Void> dataProvider = DataProvider.fromCallbacks(
                    // First callback fetches items based on a query
                    query -> {

                        // The index of the first item to load
                        int offset = query.getOffset();
                        // The number of items to load
                        int limit = query.getLimit();

                        List list = DAO.findAllWithRigts(offset, limit, getCurrentClass());


                    // Second callback fetches the number of items for a query
                    query -> totalCount

Grid grid = new Grid<>();
            grid.addColumn(new ComponentRenderer<>(object ->{
                VerticalLayout box = new VerticalLayout();
                 Label lName = new Label(object.getName());

                return box;

I have exactly the same problem since updating from Vaadin 8 to Vaadin 14.

Yes, it’s way too slow with 500+ rows…

query → totalCount

I noticed one detail here. You seem to return allways the total count. The query should return the number of items fetched, i.e. should match the first query. This may be the culprit for the slowness.

Hi Tatu,

I think the documentation is somewhat misleading here.
If you look at:

you see that it returns getPersonCount() and it is not using any offset or limit values.

If you’re right than there is another problem: Why must I go through all items (expensive database operation with materializing and discarding) to find out how many should be there if the first query already returns all materialized items?


I remember you implemented the Filesystem Data Provider and had a quick look:

Now I’m puzzled even more:

  1. I can’t see where offset/limit is used in fetchChildren where getChildrenFromFilesystem gets called
  2. in getChildCount you also call fetchChildren. So what’s the use case for the count methods?

Thank you

Tatu gave you a bit of wrong info, the second lambda should return the the total size of the dataset, NOT the size returned by first callback. Your optimisation (returning always pre-fetched count) looks just fine to me if you can trust that the data set doesn’t change.

Could you check (with for example using logging) that the callbacks are not called multiple times? If that isn’t the case, then it is probably some odd situation in the Grid component itself. Could somebody share the full example code that we could investigate?


I created a new ticket for discussing the documentation:

I have same problem with Vaadin 14. I think DataProvider.fromCallbacks working in UI thread, because invoked from DataProvider.refreshAll(). It is unuseful grid scrolling with a lot of rows in it. Anybody solved this?