Report Generation issue onBeforeCommitChanges - com.haulmont.cuba.core.global.EntityAccessException: Unable to load entity bpd_Invoice-9d2ce31c-bf24-4766-d6c6-65c02da21ef6 because it has been deleted or access denied

Hi,

I am calling below piece of code from onBeforeCommitChanges event by passing Invoice entity which is not yet saved in DB.

Unable to generate the report with error - Caused by: com.haulmont.cuba.core.global.EntityAccessException: Unable to load entity bpd_Invoice-9d2ce31c-bf24-4766-d6c6-65c02da21ef6 because it has been deleted or access denied
at com.haulmont.cuba.core.app.DataManagerBean.reload(DataManagerBean.java:118) ~[cuba-core-7.2.16.jar:7.2.16]

Any help will be appreciated.

Source Code:

 @Override
    public void generateReport(String invoiceId, String fileName,Invoice invoice) {
        try{
            Report report = dataService.load(
                    LoadContext.create(Report.class).setQuery(
                            LoadContext.createQuery("select e from report$Report e where e.code = :reportCode")
                                    .setParameter("reportCode", INVOICE_REPORT_CODE)
                    )
            );

            Map<String, Object> params = ParamsMap.of("entity", invoice);

            FileDescriptor reportFileDescriptor = reportService.createAndSaveReport(report, params, fileName);

            logger.info("reportFileDescriptor::"+reportFileDescriptor);
        }catch(Exception e){
            logger.error("Exception from generateSPInvoice::",e);
        }
    }

Hi,
You can’t use reports with datasets of “Entity” type for entity instances that haven’t been saved yet, because reporting engine always reload such entities.

You may try to use Groovy dataset. You can access entity passed as a parameter in the following way:

Thank you. Issue resolved.