我正在尝试使用jasper插件生成doc格式的报告,异常生成于:
JasperReportDef report = jasperService.buildReportDefinition(params, request.getLocale(), result)
在我的控制器中排队
例外:
could not initialize proxy - no Session. Stacktrace follows:
org.hibernate.LazyInitializationException: could not initialize proxy - no Session
at org.apache.commons.beanutils.PropertyUtilsBean.invokeMethod(PropertyUtilsBean.java:2170)
at org.apache.commons.beanutils.PropertyUtilsBean.getSimpleProperty(PropertyUtilsBean.java:1332)
at org.apache.commons.beanutils.PropertyUtilsBean.getNestedProperty(PropertyUtilsBean.java:770)
at org.apache.commons.beanutils.PropertyUtilsBean.getProperty(PropertyUtilsBean.java:846)
at org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.java:426)
at net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getBeanProperty(JRAbstractBeanDataSource.java:111)
at net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getFieldValue(JRAbstractBeanDataSource.java:96)
at net.sf.jasperreports.engine.data.JRBeanCollectionDataSource.getFieldValue(JRBeanCollectionDataSource.java:100)
at net.sf.jasperreports.engine.fill.JRFillDataset.setOldValues(JRFillDataset.java:1317)
at net.sf.jasperreports.engine.fill.JRFillDataset.next(JRFillDataset.java:1218)
at net.sf.jasperreports.engine.fill.JRFillDataset.next(JRFillDataset.java:1194)
at net.sf.jasperreports.engine.fill.JRBaseFiller.next(JRBaseFiller.java:1544)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:142)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:909)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:841)
at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:88)
at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:653)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:969)
at com.cvsurgeon.DownloadCVController$_closure3.doCall(DownloadCVController.groovy:563)
at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:195)
at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63)
at java.lang.Thread.run(Thread.java:662)
我用google搜索并发现了一些替代品,但在我的情况下不起作用,如: How to use jasperreports subreports with grails jasper plugin?
任何帮助将不胜感激。
答案 0 :(得分:0)
恕我直言,问题在于您使用域对象组成的数据填充报表。
这些域对象的某些属性在生成报告时是延迟加载的,但会话不可用,因此错误。
我看到三种可能的解决方案:
在服务中调用jasperService.buildReportDefinition而不是控制器 - 会话应该在那里可用。
不使用域对象填充报表,而是将必要的数据复制到DTO并使用它。
确定哪些属性是延迟加载的并使其急切加载 - 请参阅http://grails.org/doc/latest/guide/GORM.html#fetching