java - 错误: Hibernate could not initialize proxy - no Session

标签 java hibernate

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.

最佳答案

这意味着您有一个具有惰性 fetchType 的集合。

you can solve it by changing it to EAGER mode

因此,转到 ReportService 类并将员工集合的 fetchType 更改为 EAGER。或者添加 (fetch=fetch = FetchType.EAGER)

关于java - 错误: Hibernate could not initialize proxy - no Session,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46444869/

相关文章:

java - 位置管理器的 AddGpsStatusListener 在 Android 10 中不起作用

java - RxJava2 如何在调用它的方法中返回 onSuccess 的结果?

java - 为树集增加值(value)

java - JPA - 多对多作为 ElementCollection

java - 用于 keystore 和信任库优势的相同 JKS 文件

java - 在 Eclipse 3.7 中编译时有什么方法可以隐藏某些代码片段吗?

java - JPA:有条件地获取一些子对象

java - Hibernate 基本示例不起作用

java.sql.SQLException : Field foreign_key doesn't have a default value

hibernate 条件 : Eagerly load ManyToMany collection