Suppose i have an Order and OrderLine entities, with a composition relationship.
I’ve coded the following entity listener:
@EventListener
public void onPosOrderChangedBeforeCommit(final EntityChangedEvent<PosOrder> event) {
if (event.getType() == EntityChangedEvent.Type.CREATED) {
Id<PosOrder> posOrderId = event.getEntityId();
PosOrder posOrder = dataManager.load(posOrderId).one();
List<OrderLine> orderLineList = posOrder.getOrderLines();
for (OrderLine orderLine : orderLineList) {
log.info(orderLine.getQuantity().toPlainString());
subtractProductStock(orderLine.getProduct().getId(), orderLine.getQuantity());
}
}
if (event.getType() == EntityChangedEvent.Type.DELETED) {
Id<PosOrder> oldOrderId = event.getEntityId();
log.info("Old Order Id: {}",event.getEntityId());
UUID oldOrderUUID = (UUID) oldOrderId.getValue();
List<OrderLine> orderLineList = dataManager.load(OrderLine.class)
.query("select e from OrderLine e where e.posOrder.id = :posOrderId")
.parameter("posOrderId", oldOrderUUID)
.list();
for (OrderLine orderLine : orderLineList) {
log.info(orderLine.getQuantity().toPlainString());
addProductStock(orderLine.getProduct().getId(), orderLine.getQuantity());
}
}
}
In this case, when a PosOrder is deleted entirely from the PosOrder list view, the line:
List<OrderLine> orderLineList = dataManager.load(OrderLine.class)
is returning an empty list, even though there actually are entites related.
Why is that? How can i achieve my purpose?