简体   繁体   English

错误:休眠无法初始化代理-没有会话

[英]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.

相关问题 Hibernate无法初始化代理 - 没有Session - Hibernate could not initialize proxy - no Session HIbernate - 尝试获取数据时出现“无法初始化代理 - 无会话”错误 - HIbernate - "could not initialize proxy - no Session" error when trying to fetch data 错误org.hibernate.LazyInitializationException - 无法初始化代理 - 没有会话 - ERROR org.hibernate.LazyInitializationException - could not initialize proxy - no Session Hibernate / Spring3:无法初始化代理 - 没有Session - Hibernate/Spring3: could not initialize proxy - no Session Hibernate中的LazyInitializationException:无法初始化代理 - 没有Session - LazyInitializationException in Hibernate : could not initialize proxy - no Session 休眠延迟异常无法初始化代理-无会话 - hibernate lazy exception could not initialize proxy - no Session Hibernate LazyInitializationException:无法初始化代理-没有会话 - Hibernate LazyInitializationException: could not initialize proxy - no Session Hibernate 无法延迟初始化角色集合 无法初始化代理 - 没有 Session - Hibernate failed to lazily initialize a collection of role could not initialize proxy - no Session 休眠-无法延迟初始化角色集合:无法初始化代理-没有会话 - Hibernate - failed to lazily initialize a collection of role: could not initialize proxy - no Session 休眠问题:org.hibernate.LazyInitializationException:无法初始化代理-没有会话 - Hibernate issue: org.hibernate.LazyInitializationException: could not initialize proxy - no Session
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM