[英]Error: Hibernate could not initialize proxy - no Session
ReportService Code ReportService代码
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.
我正在尝试执行一个将打开jasper报告模板的函数。
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.
如果该功能仅处理数据库中的1名员工,则该功能有效,但是如果我在同一日期处理更多员工,则表示Hibernate无法初始化代理-没有会话。
This means that you have one collection with lazy fetchType. 这意味着您有一个带有延迟fetchType的集合。
you can solve it by changing it to EAGER mode
您可以将其更改为EAGER模式来解决
So go to ReportService
class and turn your employee collection's fetchType to EAGER
. 因此,转到
ReportService
类,然后将员工集合的fetchType转换为EAGER
。 Or add (fetch=fetch = FetchType.EAGER)
或添加
(fetch=fetch = FetchType.EAGER)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.