简体   繁体   中英

Jasper plugin in Grails: org.hibernate.LazyInitializationException: could not initialize proxy - no Session

I am trying generate report in doc format using jasper plugin, exception is generated at:

JasperReportDef report = jasperService.buildReportDefinition(params, request.getLocale(), result) 

line in my controller

Exception:

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)

I have googled and found some alternate but not works in my case like: How to use jasperreports subreports with grails jasper plugin?

any help will be appreciated.

IMHO the problem is that you are filling the report with data that are consisted of domain objects.

Some properties of these domain objects are lazy-loaded at the time when the report is generated, but Session is not available hence the error.

I see three possible solutions:

  1. Do a call of jasperService.buildReportDefinition in a service instead of controller - session should be available there.

  2. Instead of using domain objects to fill the report, copy necessary data to a DTO and use it.

  3. Identify which properties are lazily-loaded and make them eagerly-loaded instead - see http://grails.org/doc/latest/guide/GORM.html#fetching

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM