In the Legacy version, the following code works to load the details of
MaterialRequisition requisition = dataManager.load(MaterialRequisition.class)
.query("select e from erp$MaterialRequisition e where e.id = :reqId")
.parameter("reqId", getItem().getMaterialRequisition().getId())
.view("materialRequisition-view")
.optional().orElse(null);
getItem().setPlant(requisition.getPlant());
for(MaterialRequisitionLine line : requisition.getMaterialRequisitionLine()){
PurchaseRequisitionLine requisitionLine = metadata.create(PurchaseRequisitionLine.class);
requisitionLine.setMaterial(line.getMaterial());
requisitionLine.setUnitOfMeasure(line.getUnitOfMeasure());
requisitionLine.setPurchaseRequisition(getEditedEntity());
requisitionLine.setMaterialRequisitionLine(line);
purchaseRequisitionLineDs.add(requisitionLine);
}
However, the following similar code in platform V7 doesn’t work, giving exception
MaterialRequisition requisition = dataManager.load(MaterialRequisition.class)
.query("select e from erp$MaterialRequisition e where e.id = :reqId")
.parameter("reqId", getEditedEntity().getMaterialRequisition().getId())
.view("materialRequisition-view")
.optional().orElse(null);
getEditedEntity().setPlant(requisition.getPlant());
for(MaterialRequisitionLine line : requisition.getMaterialRequisitionLine()){
PurchaseRequisitionLine requisitionLine = metadata.create(PurchaseRequisitionLine.class);
requisitionLine.setMaterial(line.getMaterial());
requisitionLine.setUnitOfMeasure(line.getUnitOfMeasure());
requisitionLine.setPurchaseRequisition(getEditedEntity());
requisitionLine.setMaterialRequisitionLine(line);
purchaseRequisitionLineDc.getMutableItems().add(requisitionLine);
}
The exception i get is:
IllegalStateException: During synchronization a new object was found through a relationship that was not marked cascade PERSIST: com.myapp.entity.proc.PurchaseRequisitionLine-f62163e2-7c0a-6589-d6c9-e4f5bb1a203a [new].
Thanks for helping where and what I am missing in V7 code.