Grid column: displaying data from ManyToMany field

Hi, In my View I display a Vaadin Grid grid = new Grid<>(Ticket.class, false). I add some columns for specific fields of the Ticket entity. Now there’s my problem/misunderstanding. The ticket entity also has a field “gewaesser” which is annotated with @ManyToMany. I want to display the names of gewaesser’s in a grid column named “Gewässer”. I do this as follows:

grid.addColumn(new ComponentRenderer<>(ticket -> {
    div = new Div();
// remark: getGewaessernamen(ticketId) returns a Set<String> with the names of gewaesser
    div.setText(ticketService.getGewaessernamen(ticket.getId()).stream().collect(Collectors.joining(", ")));

    return div;

This is working fine. However I’m feeling this is not the best and performant way to load the data associated with the ticket instance. Am I right? If not can anyone give some advice how to do it in a more performant and elegant way? Thanks in advance :slightly_smiling_face:

Instead of using a component renderer, you can return a string, which will be more lightweight to render. Something like this:

grid.addColumn(ticket -> 
    ticketService.getGewaessernamen(ticket.getId()).stream().collect(Collectors.joining(", "))