我有Renderer
类,其内部逻辑使用hibernate来获取数据,例如:
result = getSession().load(getBeanClass(), id);
奇怪的是,$P{renderer}.render($F{data}.get("ID"))
在主报表中使用时工作正常,在子报表中使用它时失败,但有以下异常:
Caused by: net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression for source text: $P{renderer}.render($F{data}.get("ID"))
at net.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:264)
at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:610)
at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:578)
at net.sf.jasperreports.engine.fill.JRFillElement.evaluateExpression(JRFillElement.java:1015)
at net.sf.jasperreports.engine.fill.JRFillTextField.evaluateText(JRFillTextField.java:572)
at net.sf.jasperreports.engine.fill.JRFillTextField.evaluate(JRFillTextField.java:556)
at net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFillElementContainer.java:258)
at net.sf.jasperreports.engine.fill.JRFillBand.evaluate(JRFillBand.java:454)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillColumnBand(JRVerticalFiller.java:2029)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillDetail(JRVerticalFiller.java:755)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:262)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:122)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:551)
at net.sf.jasperreports.engine.fill.BaseReportFiller.fill(BaseReportFiller.java:411)
at net.sf.jasperreports.engine.fill.JRFillSubreport.fillSubreport(JRFillSubreport.java:732)
at net.sf.jasperreports.engine.fill.JRSubreportRunnable.run(JRSubreportRunnable.java:58)
at net.sf.jasperreports.engine.fill.AbstractThreadSubreportRunner.run(AbstractThreadSubreportRunner.java:216)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
... 1 more
Caused by: org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current thread
我做了调试,发现Spring 4.3.3
失败的地方:
if(TransactionSynchronizationManager.isSynchronizationActive()) { // returns false here when renderer invoked from subreport
//...
} else {
throw new HibernateException("Could not obtain transaction-synchronized Session for current thread");
}
问题:
主要问题是从MainReport调用和从SubReport调用如何改变TransactionSynchronizationManager.isSynchronizationActive()
的情况?你知道如何解决这个问题吗?