Hi Team,
I have to implement the copy mechanism of entity which is having composition relationship with other entity. For example Invoice entity having Invoice lines.
I am able to go thru sample project (copy.zip) there it has mentioned to user openEdition() method.
when i tried the same way, I am losing the Invoice Lines in invoice object.
Please suggest me how can i save copied entity which contains the relationship.
Regards,
Nagendra.
krivopustov
(Konstantin Krivopustov)
September 6, 2017, 12:58pm
#2
Hi Nagendra,
Please attach a test project where we could reproduce your problem.
Hi Konstantin,
Please find the attached project.
There are two entities in the project
Invoice
Invoice Lines
Regards,
Nagendra.
modules.zip (239.0K)
krivopustov
(Konstantin Krivopustov)
September 9, 2017, 10:38am
#4
Thanks for sending the test code.
Solution is simple: you should copy InvoiceLine instances as well:
public class InvoiceBrowse extends AbstractLookup {
@Inject
private GroupTable<Invoice> invoicesTable;
@Inject
private GroupDatasource<Invoice, UUID> invoicesDs;
@Inject
private Metadata metadata;
public void onCopyBtnClick() {
Invoice invoice = invoicesTable.getSingleSelected();
if (invoice != null) {
Invoice copyInvoice = metadata.create(Invoice.class);
copyInvoice.setDate(invoice.getDate());
copyInvoice.setDescription(invoice.getDescription());
copyInvoice.setNumber(invoice.getNumber());
copyInvoice.setInvoicelines(new HashSet<>());
for (InvoiceLine invoiceLine : invoice.getInvoicelines()) {
InvoiceLine copyLine = metadata.create(InvoiceLine.class);
copyLine.setInvoice(copyInvoice);
copyLine.setAmount(invoiceLine.getAmount());
copyLine.setEmployee(invoiceLine.getEmployee());
copyLine.setProjectName(invoiceLine.getProjectName());
copyInvoice.getInvoicelines().add(copyLine);
}
openEditor(copyInvoice, WindowManager.OpenType.THIS_TAB).addCloseWithCommitListener(() -> invoicesDs.refresh());
}
}
}
See the working project attached.
invoicecopy.zip (31.4K)