2011-12-27 30 views
5

我有一个Hibernate POJO与 1.an一个-to-one关联到另一个对象 2.one-to-many关联(集合)与另一个对象传递一个POJO中贾斯帕报表报告

我我试图用这些关联创建一个Jasper报告到子报表。 对于许多-to-one关联我传递的数据源如下:

<subreport> 
<reportElement x="40" y="16" width="100" height="30"/> 
<dataSourceExpression> 
    <![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{phones})]]> 
</dataSourceExpression> 
<subreportExpression> 
    <![CDATA[$P{SUBREPORT_DIR} + "subreport1.jasper"]]> 
</subreportExpression> 
</subreport> 

这工作得很好。这里是我定义它为一个-to-one关联

<subreport> 
<reportElement x="25" y="91" width="200" height="59"/> 
<dataSourceExpression> 
    <![CDATA[new net.sf.jasperreports.engine.data.JRBeanArrayDataSource([$F{batchHeaderRecord}] as java.lang.Object[])]]> 
</dataSourceExpression> 
<subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "batchHeaderReport.jasper"]]> 
</subreportExpression> 
</subreport> 

的方式,但这个是行不通的。有人可以让我知道我要去哪里吗?

+0

什么是$ F {batchHeaderRecord}字段的类型? – 2011-12-27 13:21:10

回答

5
new net.sf.jasperreports.engine.data.JRBeanArrayDataSource([$F{batchHeaderRecord}] as java.lang.Object[]) 

是无效的Java代码。只需使用

new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource(java.util.Collections.singleton($F{batchHeaderRecord})) 

new net.sf.jasperreports.engine.data.JRBeanArrayDataSource(new Object[] {$F{batchHeaderRecord}}) 
+0

谢谢..让他们出来。 JRBeanCollectionDataSource工作正常。但是使用JRBeanArrayDataSource会给我以下错误:net.sf.jasperreports.engine.JRException:编译报表表达式类文件时遇到错误:org.codehaus.groovy.control.MultipleCompilationErrorsException:启动失败:calculator_tdsSample_1325043312140_397478:187:表达式为数组构造函数调用在行:187列:91.文件:calculator_tdsSample_1325043312140_397478 @ line 187,column 91 – PrasanthNath 2011-12-28 04:10:26

+0

嗨, 我面临同样的问题。但具有不同的场景。我试图显示表中的列表,但我的列表与另一个实体如MemberList具有一对一的关系,与雇员有一对一的关系 我想显示Member_ID | Employee.FullName |在同一张桌子里。 请帮忙 – 2017-12-21 06:10:12

1

套装language的Java报表修复常规错误。