2017-09-27 110 views
0

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.

+0

錯誤的堆棧跟蹤會有幫助 – ChristopherZ

回答

1

這意味着你有一個集懶fetchType。

you can solve it by changing it to EAGER mode

所以去ReportService類,並把你的員工收集的fetchType到EAGER。或者添加(fetch=fetch = FetchType.EAGER)

+0

該函數有太多的模型。我將展示哪種特定的模型?感謝你的回答。 :) – cleem

+0

ReportService和員工!!! – devuser

+0

我的意思是薪資和員工! – devuser

相關問題