Count entries in a related table

How do I count the entries (Size) of a Collection related to another table?
Ordrer has many Lines (Count lines) and show line count in a column in Ordrer table.

First, ensure the related collection is loaded - include the collection attribute to the view.
To display the count in a table, use generated column (see addGeneratedColumn() method in the docs).
Something like this:


ordersTable.addGeneratedColumn("linesCount", new Table.ColumnGenerator<Order>() {
    @Override
    public Component generateCell(Order order) {
        Label label = componentsFactory.createComponent(Label.NAME);
        label.setValue(order.getLines().size());
        return label;
    }
});