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