Even if I remove it from the data container, it is saved to the database

public void onRemoveItemAction(Div div, OrderItem orderItem) {
        amount = amount.subtract(orderItem.getAmount());
        setValue(amountSpan, amount);
        itemsSpan.setText(String.valueOf(--itemsNumber));
        orderItemsDc.getMutableItems().remove(orderItem);
        orderItems.remove(div);

        if (orderItemsDc.getItems().isEmpty()) {
            saveAction.setEnabled(false);
            warehouse.setEnabled(true);
            addItem.setEnabled(true);
        }
    }

Order items are linked to an order in this case:

@Composition
@OneToMany(mappedBy = "order")
@OrderBy("item")
@OnDelete(DeletePolicy.CASCADE)
private List<OrderItem> items;

Now the orderItem is deleted in orderItemsDc but the database has that deleted orderItem save

Mark it also as removed in DataContext:

@ViewComponent
private DataContext dataContext;

public void onRemoveItemAction(Div div, OrderItem orderItem) {
        // ...
        orderItemsDc.getMutableItems().remove(orderItem);
        dataContext.remove(orderItem)

Then it will be deleted when the view is saved.

1 Like

It worked, thank you very much