I have this scenario where I need to reorganise items in a CollectionContainer.
Suppose each SalesOrder has many items, with type: SalesOrderItem.
Now, in the code, I try to do the following:
Map<SaleItem, SalesOrderItem> orderItems = orderItemsDc.getItems()
.stream()
.filter(o -> o.getCancelledBy() == null &&
o.getComplimentaryBy() == null &&
!o.getItem().getCategory().getName().equals("Billiard"))
.collect(Collectors.toMap(SalesOrderItem::getItem, item -> {
item.setPrinted(true);
return item;
}, (item1, item2) -> {
item1.setQty(item1.getQty() + item2.getQty());
item1.setTotalPrice(item1.getTotalPrice() + item2.getTotalPrice());
item1.setPrinted(true);
dataManager.save(item1);
dataManager.remove(item2);
return item1;
}));
The problem, if I simply do that, the dataContext will think that the tracked entity still dirty. And if I use dataContext.save
then it will results in data duplicates.
Any idea on how we can do this? More specifically, I wonder why dataManager doesn’t really remove the Entity and that it doesn’t work together with the dataContext.