title: JasperReports: Subreport renders multiple times, causing duplicate pages
body: <p>I am using <em>JasperReports</em> to generate a graph and table for a web application using two separate queries. My main <em>JRXML</em> generates the graph, and I include a subreport in the <strong><em>Detail</em></strong> band to generate the table. However, when it renders, the subreport seems to get rendered multiple times (12 to be exact), which results in the generated report being the same graph and table on 12 pages (exact duplicates of each other). This happens both through the online application and <em>iReport</em>.</p>
  
  <p>My main <em>JRXML</em>, subreport <em>JRXML</em>, and report generation code are below (some details have been removed for NDA reasons).</p>
  
  <p>Any insight or ideas on what the issue is would be very helpful.</p>
  
  <p>Main <em>JRXML</em>:</p>
  
  <pre class="lang-xml prettyprint-override"><code>    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
      &lt;jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="report" language="groovy" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20"&gt;
          &lt;property name="ireport.zoom" value="1.0"/&gt;
          &lt;property name="ireport.x" value="0"/&gt;
          &lt;property name="ireport.y" value="0"/&gt;
          &lt;parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false"&gt;
              &lt;defaultValueExpression&gt;&lt;![CDATA["&lt;&lt;PATH_TO_SUBREPORT&gt;&gt;"]]&gt;&lt;/defaultValueExpression&gt;
          &lt;/parameter&gt;
          &lt;parameter name="param" class="java.util.Collection" /&gt;     
       &lt;queryString language="SQL"&gt;
              &lt;![CDATA[&lt;&lt;DATABASE_QUERY&gt;&gt;]]&gt;
          &lt;/queryString&gt;
          &lt;field name="FIELD1" class="java.lang.Integer"/&gt;
          &lt;field name="FIELD2" class="java.sql.Date"/&gt;
          &lt;field name="FIELD3" class="java.math.BigDecimal"/&gt;
          &lt;field name="FIELD4" class="java.math.BigDecimal"/&gt;
          &lt;field name="FIELD5" class="java.math.BigDecimal"/&gt;
          &lt;background&gt;
              &lt;band splitType="Stretch"/&gt;
          &lt;/background&gt;
          &lt;title&gt;
              &lt;band height="10" splitType="Stretch"/&gt;
          &lt;/title&gt;
          &lt;pageHeader&gt;
              &lt;band height="5" splitType="Stretch"/&gt;
          &lt;/pageHeader&gt;
          &lt;columnHeader&gt;
              &lt;band height="5" splitType="Stretch"/&gt;
          &lt;/columnHeader&gt;
          &lt;detail&gt;
              &lt;band height="513" splitType="Stretch"&gt;
                  &lt;lineChart&gt;
                      &lt;chart&gt;
                          &lt;reportElement positionType="Float" x="51" y="0" width="680" height="400"/&gt;
                          &lt;chartTitle/&gt;
                          &lt;chartSubtitle/&gt;
                          &lt;chartLegend/&gt;
                      &lt;/chart&gt;
                      &lt;categoryDataset&gt;
                          &lt;categorySeries&gt;
                              &lt;seriesExpression&gt;&lt;![CDATA["FIELD1"]]&gt;&lt;/seriesExpression&gt;
                              &lt;categoryExpression&gt;&lt;![CDATA[$F{f1}]]&gt;&lt;/categoryExpression&gt;
                              &lt;valueExpression&gt;&lt;![CDATA[$F{f2}]]&gt;&lt;/valueExpression&gt;
                          &lt;/categorySeries&gt;
                          &lt;categorySeries&gt;
                              &lt;seriesExpression&gt;&lt;![CDATA["FIELD2"]]&gt;&lt;/seriesExpression&gt;
                              &lt;categoryExpression&gt;&lt;![CDATA[$F{f1}]]&gt;&lt;/categoryExpression&gt;
                              &lt;valueExpression&gt;&lt;![CDATA[$F{f2}]]&gt;&lt;/valueExpression&gt;
                          &lt;/categorySeries&gt;
                          &lt;categorySeries&gt;
                              &lt;seriesExpression&gt;&lt;![CDATA["FIELD3"]]&gt;&lt;/seriesExpression&gt;
                              &lt;categoryExpression&gt;&lt;![CDATA[$F{f1}]]&gt;&lt;/categoryExpression&gt;
                              &lt;valueExpression&gt;&lt;![CDATA[$F{f2}]]&gt;&lt;/valueExpression&gt;
                          &lt;/categorySeries&gt;
                      &lt;/categoryDataset&gt;
                      &lt;linePlot&gt;
                          &lt;plot labelRotation="-90.0"/&gt;
                          &lt;categoryAxisFormat labelRotation="-90.0"&gt;
                              &lt;axisFormat&gt;
                                  &lt;tickLabelFont&gt;
                                      &lt;font size="12"/&gt;
                                  &lt;/tickLabelFont&gt;
                              &lt;/axisFormat&gt;
                          &lt;/categoryAxisFormat&gt;
                          &lt;rangeAxisMinValueExpression&gt;&lt;![CDATA[0]]&gt;&lt;/rangeAxisMinValueExpression&gt;
                          &lt;rangeAxisMaxValueExpression&gt;&lt;![CDATA[101]]&gt;&lt;/rangeAxisMaxValueExpression&gt;
                      &lt;/linePlot&gt;
                  &lt;/lineChart&gt;
                  &lt;subreport&gt;
                      &lt;reportElement x="377" y="413" width="425" height="100"/&gt;
                      &lt;subreportParameter name="param"&gt;
                          &lt;subreportParameterExpression&gt;&lt;![CDATA[$P{param}]]&gt;&lt;/subreportParameterExpression&gt;
                      &lt;/subreportParameter&gt;
                      &lt;connectionExpression&gt;&lt;![CDATA[$P{REPORT_CONNECTION}]]&gt;&lt;/connectionExpression&gt;
                      &lt;subreportExpression&gt;&lt;![CDATA[$P{SUBREPORT_DIR} + "testReport.jasper"]]&gt;&lt;/subreportExpression&gt;
                  &lt;/subreport&gt;
              &lt;/band&gt;
          &lt;/detail&gt;
          &lt;columnFooter&gt;
              &lt;band height="5" splitType="Stretch"/&gt;
          &lt;/columnFooter&gt;
          &lt;pageFooter&gt;
              &lt;band height="15" splitType="Stretch"&gt;
                  &lt;textField&gt;
                      &lt;reportElement mode="Opaque" x="3" y="2" width="759" height="13" backcolor="#E6E6E6"/&gt;
                      &lt;textElement textAlignment="Right"/&gt;
                      &lt;textFieldExpression&gt;&lt;![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]&gt;&lt;/textFieldExpression&gt;
                  &lt;/textField&gt;
                  &lt;textField evaluationTime="Report"&gt;
                      &lt;reportElement mode="Opaque" x="762" y="2" width="40" height="13" backcolor="#E6E6E6"/&gt;
                      &lt;textElement/&gt;
                      &lt;textFieldExpression&gt;&lt;![CDATA[" " + $V{PAGE_NUMBER}]]&gt;&lt;/textFieldExpression&gt;
                  &lt;/textField&gt;
                  &lt;textField pattern="EEEEE dd MMMMM yyyy"&gt;
                      &lt;reportElement x="3" y="0" width="100" height="13"/&gt;
                      &lt;textElement/&gt;
                      &lt;textFieldExpression&gt;&lt;![CDATA[new SimpleDateFormat("MM-dd-yyyy").format(
      new java.util.Date())]]&gt;&lt;/textFieldExpression&gt;
                  &lt;/textField&gt;
              &lt;/band&gt;
          &lt;/pageFooter&gt;
          &lt;summary&gt;
              &lt;band height="10" splitType="Stretch"/&gt;
          &lt;/summary&gt;
      &lt;/jasperReport&gt;
  </code></pre>
  
  <p>Sub Report <em>JRXML</em>:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="evcas_sub" language="groovy" pageWidth="450" pageHeight="150" columnWidth="10" leftMargin="10" rightMargin="10" topMargin="10" bottomMargin="10"&gt;
      &lt;property name="ireport.zoom" value="1.0"/&gt;
      &lt;property name="ireport.x" value="0"/&gt;
      &lt;property name="ireport.y" value="0"/&gt;
      &lt;style name="table"&gt;
          &lt;box&gt;
              &lt;pen lineWidth="1.0" lineColor="#000000"/&gt;
          &lt;/box&gt;
      &lt;/style&gt;
      &lt;style name="table_TH" mode="Opaque" backcolor="#0000FF"&gt;
          &lt;box&gt;
              &lt;pen lineWidth="0.5" lineColor="#000000"/&gt;
          &lt;/box&gt;
      &lt;/style&gt;
      &lt;style name="table_CH" mode="Opaque" backcolor="#BFBFFF"&gt;
          &lt;box&gt;
              &lt;pen lineWidth="0.5" lineColor="#000000"/&gt;
          &lt;/box&gt;
      &lt;/style&gt;
      &lt;style name="table_TD" mode="Opaque" backcolor="#FFFFFF"&gt;
          &lt;box&gt;
              &lt;pen lineWidth="0.5" lineColor="#000000"/&gt;
          &lt;/box&gt;
          &lt;conditionalStyle&gt;
              &lt;conditionExpression&gt;&lt;![CDATA[new Boolean($V{REPORT_COUNT}.intValue()%2==0)]]&gt;&lt;/conditionExpression&gt;
              &lt;style backcolor="#EFEFFF"/&gt;
          &lt;/conditionalStyle&gt;
      &lt;/style&gt;
      &lt;style name="Crosstab Data Text" hAlign="Center"/&gt;
      &lt;parameter name="param" class="java.util.Collection" /&gt;
      &lt;queryString&gt;
          &lt;![CDATA[&lt;&lt;DATABASE_QUERY&gt;&gt;]]&gt;
      &lt;/queryString&gt;
      &lt;field name="FIELD1" class="java.lang.String"/&gt;
      &lt;field name="FIELD2" class="java.math.BigDecimal"/&gt;
      &lt;field name="FIELD3" class="java.math.BigDecimal"/&gt;
      &lt;field name="FIELD4" class="java.math.BigDecimal"/&gt;
      &lt;field name="FIELD5" class="java.math.BigDecimal"/&gt;
      &lt;field name="FIELD6" class="java.math.BigDecimal"/&gt;
      &lt;field name="FIELD7" class="java.math.BigDecimal"/&gt;
      &lt;field name="FIELD8" class="java.math.BigDecimal"/&gt;
      &lt;background&gt;
          &lt;band splitType="Stretch"/&gt;
      &lt;/background&gt;
      &lt;title&gt;
          &lt;band height="5" splitType="Stretch"/&gt;
      &lt;/title&gt;
      &lt;pageHeader&gt;
          &lt;band height="5"/&gt;
      &lt;/pageHeader&gt;
      &lt;columnHeader&gt;
          &lt;band height="12"&gt;
              &lt;textField&gt;
                  &lt;reportElement style="table_TH" x="0" y="0" width="50" height="12" backcolor="#FFFFFF"/&gt;
                  &lt;textElement&gt;
                      &lt;font size="9"/&gt;
                      &lt;paragraph leftIndent="2"/&gt;
                  &lt;/textElement&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA["FIELD1"]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;
              &lt;textField&gt;
                  &lt;reportElement style="table_TH" x="50" y="0" width="50" height="12" backcolor="#FFFFFF"/&gt;
                  &lt;textElement&gt;
                      &lt;font size="9"/&gt;
                      &lt;paragraph leftIndent="2"/&gt;
                  &lt;/textElement&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA["FIELD2"]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;
              &lt;textField&gt;
                  &lt;reportElement style="table_TH" x="100" y="0" width="50" height="12" backcolor="#FFFFFF"/&gt;
                  &lt;textElement&gt;
                      &lt;font size="9"/&gt;
                      &lt;paragraph leftIndent="2"/&gt;
                  &lt;/textElement&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA["FIELD3"]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;
              &lt;textField&gt;
                  &lt;reportElement style="table_TH" x="150" y="0" width="50" height="12" backcolor="#FFFFFF"/&gt;
                  &lt;textElement&gt;
                      &lt;font size="9"/&gt;
                      &lt;paragraph leftIndent="2"/&gt;
                  &lt;/textElement&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA["FIELD4"]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;
              &lt;textField&gt;
                  &lt;reportElement style="table_TH" x="200" y="0" width="50" height="12" backcolor="#FFFFFF"/&gt;
                  &lt;textElement&gt;
                      &lt;font size="9"/&gt;
                      &lt;paragraph leftIndent="2"/&gt;
                  &lt;/textElement&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA["FIELD5"]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;
              &lt;textField&gt;
                  &lt;reportElement style="table_TH" x="250" y="0" width="50" height="12" backcolor="#FFFFFF"/&gt;
                  &lt;textElement&gt;
                      &lt;font size="9"/&gt;
                      &lt;paragraph leftIndent="2"/&gt;
                  &lt;/textElement&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA["FIELD6"]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;
              &lt;textField&gt;
                  &lt;reportElement style="table_TH" x="300" y="0" width="50" height="12" backcolor="#FFFFFF"/&gt;
                  &lt;textElement&gt;
                      &lt;font size="9"/&gt;
                      &lt;paragraph leftIndent="2"/&gt;
                  &lt;/textElement&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA["FIELD7"]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;
              &lt;textField&gt;
                  &lt;reportElement style="table_TH" x="350" y="0" width="50" height="12" backcolor="#FFFFFF"/&gt;
                  &lt;textElement&gt;
                      &lt;font size="9"/&gt;
                      &lt;paragraph leftIndent="2"/&gt;
                  &lt;/textElement&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA["FIELD8"]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;
          &lt;/band&gt;
      &lt;/columnHeader&gt;
      &lt;detail&gt;
          &lt;band height="12"&gt;
              &lt;textField&gt;
                  &lt;reportElement style="table_CH" x="0" y="0" width="50" height="12" backcolor="#FFFFFF"/&gt;
                  &lt;textElement&gt;
                      &lt;font size="8"/&gt;
                      &lt;paragraph leftIndent="2"/&gt;
                  &lt;/textElement&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA[$F{f1}]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;
              &lt;textField&gt;
                  &lt;reportElement style="table_CH" x="50" y="0" width="50" height="12" backcolor="#FFFFFF"/&gt;
                  &lt;textElement&gt;
                      &lt;font size="8"/&gt;
                      &lt;paragraph leftIndent="2"/&gt;
                  &lt;/textElement&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA[$F{f2}]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;
              &lt;textField&gt;
                  &lt;reportElement style="table_CH" x="100" y="0" width="50" height="12" backcolor="#FFFFFF"/&gt;
                  &lt;textElement&gt;
                      &lt;font size="8"/&gt;
                      &lt;paragraph leftIndent="2"/&gt;
                  &lt;/textElement&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA[$F{f3}]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;
              &lt;textField&gt;
                  &lt;reportElement style="table_CH" x="150" y="0" width="50" height="12" backcolor="#FFFFFF"/&gt;
                  &lt;textElement&gt;
                      &lt;font size="8"/&gt;
                      &lt;paragraph leftIndent="2"/&gt;
                  &lt;/textElement&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA[$F{f4}]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;
              &lt;textField&gt;
                  &lt;reportElement style="table_CH" x="200" y="0" width="50" height="12" backcolor="#FFFFFF"/&gt;
                  &lt;textElement&gt;
                      &lt;font size="8"/&gt;
                      &lt;paragraph leftIndent="2"/&gt;
                  &lt;/textElement&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA[$F{f5}]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;
              &lt;textField&gt;
                  &lt;reportElement style="table_CH" x="250" y="0" width="50" height="12" backcolor="#FFFFFF"/&gt;
                  &lt;textElement&gt;
                      &lt;font size="8"/&gt;
                      &lt;paragraph leftIndent="2"/&gt;
                  &lt;/textElement&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA[$F{f6}]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;
              &lt;textField&gt;
                  &lt;reportElement style="table_CH" x="300" y="0" width="50" height="12" backcolor="#FFFFFF"/&gt;
                  &lt;textElement&gt;
                      &lt;font size="8"/&gt;
                      &lt;paragraph leftIndent="2"/&gt;
                  &lt;/textElement&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA[$F{f7}]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;
              &lt;textField&gt;
                  &lt;reportElement style="table_CH" x="350" y="0" width="50" height="12" backcolor="#FFFFFF"/&gt;
                  &lt;textElement&gt;
                      &lt;font size="8"/&gt;
                      &lt;paragraph leftIndent="2"/&gt;
                  &lt;/textElement&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA[$F{f8}]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;
          &lt;/band&gt;
      &lt;/detail&gt;
      &lt;columnFooter&gt;
          &lt;band height="5" splitType="Stretch"/&gt;
      &lt;/columnFooter&gt;
      &lt;pageFooter&gt;
          &lt;band height="5" splitType="Stretch"/&gt;
      &lt;/pageFooter&gt;
  &lt;/jasperReport&gt;
  </code></pre>
  
  <p>Rendering Code:</p>
  
  <pre class="lang-java prettyprint-override"><code>String strFileName = "&lt;&lt;FILENAME&gt;&gt;";
  File jrxml = new File(strFileName);
  InputStream iStream = new FileInputStream(jrxml);
  JasperReport objJReport = JasperCompileManager.compileReport(iStream);
  JasperPrint objJPrint = JasperFillManager.fillReport(objJReport, hashMap, datasource.getConnection());
  JasperExportManager.exportReportToPdfStream(objJPrint, os);
  </code></pre>