Hi! Faced with this problem: A large selection of data (over million record

Hi!
Faced with this problem:
A large selection of data (over million records), the task is to display it in grid.
If you fetch all the data from your data source, your app will consume more memory and will take longer to show something on the screen.
For example, you can query just the first 20 rows and when the userscrolls down the list, then you query the next 20 rows, and so forth.
You know how to do that?

I have:


1) "ENTITY"
@Entity
@Table(name="DIC_GOALS", schema="MAPP")
public class Goal {

   @Id
   @GeneratedValue(strategy = GenerationType.IDENTITY)
   @Column(name = "ID", nullable = false)
   private Long id;
   
   @Column(name = "DESCR", length = 255, nullable = false)
   public String descr;
   
   @ManyToOne
   @JoinColumn (name="UNIT_ID", nullable = false)
   public Unit unit;

   @Column(name = "VL")
   private float vl;

   public Long getId() {
       return id;
   }
 
   public void setId(Long id) {
       this.id = id;
   }
 
   public String getDescr() {
       return descr;
   }
 
   public void setDescr(String descr) {
       this.descr= descr;
   }

   public void setUnit(Unit unit) {
       this.unit = unit;
   }

    public Unit getUnit() {
        return unit;
    }

   public float getVl() {
       return vl;
   }
 
   public void setVl(float vl) {
       this.vl = vl;
   }

    @Override
    public String toString() {
        return "ID=" + id + " DESCR=" + descr + " VL=" + vl;
    }
		
}
  1. “GoalRepository”
public interface GoalRepository extends CrudRepository<Goal, Long> {

    Iterable<Goal> getGoalsByUnit (Unit unit);
    Iterable<Goal> getGoalsByUnitIn (Set<Unit> unit);
	}
  1. “SERVICE”
@Service
public class GoalServiceImpl implements GoalService {

    @Autowired
    private GoalRepository rep;

    public Goal save (Goal goal) {
        return rep.save(goal);
    }

    public Goal getById (Long id) {
        Goal goal = rep.findById(id).orElseThrow(RuntimeException::new);
        return goal;
    }

    public Iterable<Goal> getByRoles (Set<Role> roles) {
        Set<Unit> units = new HashSet<Unit>();
        roles.forEach(e -> {
                units.add(e.getUnit());
        });
        return rep.getGoalsByUnitIn(units);
    }

    public Iterable<Goal> getAll () {
        return rep.findAll();
    }

    public void deleteById (Long id) {
        rep.deleteById(id);
    }

}
  1. “GOALVIEW” - Vaadin UI
public class GoalView extends VerticalLayout {
    PaginatedGrid<Goal> grid = new PaginatedGrid<>(); 
    TextField filterText = new TextField(); 
    private GoalForm form;
    private GoalService goalService;

    public GoalView(GoalService goalService) {
        this.goalService = goalService; 
        addClassName("goal-view"); 
        setSizeFull(); 
        configureGrid(); 
        configureFilter(); 

        form = new GoalForm();
        add(filterText, grid, form); 
        updateList(); 
    }

    private void configureGrid() {
        grid.addClassName("goal-grid"); 
        grid.setSizeFull(); 
        grid.removeAllColumns();
        grid.addColumn(Goal::getId).setHeader("id").setSortable(true); 
			  grid.addColumn(Goal::getDescr).setHeader("Описание").setSortable(true);
	grid.addColumn(Goal::getVl).setHeader("Значение").setSortable(true);
        grid.addColumn(goal -> {
            Unit unit = goal.getUnit();  
            return unit == null ? "-" : unit.getName(); 
        }).setHeader("Название блока").setSortable(true); 
        grid.getColumns().forEach(col -> col.setAutoWidth(true)); 
        grid.setPageSize(4); 
        grid.setPaginatorSize(5); 

    }

    private void configureFilter() {
        filterText.setPlaceholder("Поиск по цели...");  
        filterText.setClearButtonVisible(true); 
        filterText.setValueChangeMode(ValueChangeMode.LAZY); 
        filterText.addValueChangeListener(event -> updateList()); 
    }

    private void updateList() {
        grid.setItems((Collection<Goal>)goalService.getAll(filterText.getValue());
                                                                          
    }
}

I’m not a expert in Vaadin but would like to know, what happened if you’ve used the standard Grid? Is that also not working for your above scenario?