简体   繁体   中英

Error: Hibernate could not initialize proxy - no Session

ReportService Code

 private void generatePaySummary() {
        try {
            Map params = new HashMap();
        params = getOrganizationInfo(params);
        params.put("rptsubtitle", "Payroll Date: "+date_formatter.format(tbpaydate.getDate()));

        int i = cboDept.getSelectedIndex();
        int deptno = 0;
        if (i != -1)  deptno = (Integer)deptnos.get(i);

        ReportService srv = new ReportService();
        List empids = srv.getEmployeesInPayroll(deptno, tbpaydate.getDate());
        if (!empids.isEmpty()) {
            PayslipService.setEmployees(empids);
            PayslipService.setPayDate(tbpaydate.getDate());

            RepGenService repsrv = new RepGenService();
            JRBeanCollectionDataSource jbsrc = new JRBeanCollectionDataSource(PaySummaryFactory.getPaySummary());
            repsrv.generateReport(false, "/orgpayroll/reports/jasper/payrollsummary.jasper", true, params, jbsrc);
        }
        else
            SysUtils.messageBox("No employees in payroll on "+date_formatter.format(tbpaydate.getDate())+"!");
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Error" + e.getMessage());
        }
    }

I am trying to execute a function which will open a jasper report template.

The function works if it will only process 1 employee from the database, but if I process more with the same date, it says Hibernate could not initialize proxy - no Session.

This means that you have one collection with lazy fetchType.

you can solve it by changing it to EAGER mode

So go to ReportService class and turn your employee collection's fetchType to EAGER . Or add (fetch=fetch = FetchType.EAGER)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM