Jump to content
We've recently updated our Privacy Statement, available here ×

hibernate jasperreports subreports


jochen2

Recommended Posts

Hi,

studied a lot of examples but didn´t find a solution.

 

My application runs a hibernate session , retrieves a list of CustMast-Objects

and gives them down to jasper.

 

And no the problems start:

how do I access the CustMast-Objects inside jasper?

 

so i get the following error message

and dont know what to do.

net.sf.jasperreports.engine.JRException: Error retrieving field value from bean : fMast

 

Questions

- how do i access the bean

has anybody an examler jrxml for me?

 

- is my way correct?

the subquery should access the children of CustMast

be using custmast.getKlemmes()

returning a Set of childeren.

Or am i complete worng on my way??

 

 

 

 

Code:

private DataUIResult reportMastklemmenInternal(CustLsa lsa,
DataUIResult result) throws DataException {


result = new DataUIResult();

JasperReport jasperReport;
JasperPrint jasperPrint;
HashMap<String, Object> parameter =
new HashMap<String, Object>();

Session session = null;
Transaction tx = null;
try {
session = HibernateSessionFactory.getInstance().getCurrentSession();
tx = session.beginTransaction();
CustLsa refreshedLsa = (CustLsa) refreshBeanWithinExplicitDbSession(lsa, true, true, session);
parameter.put("aLsaNr", refreshedLsa.getLsaNr() + ""«»);

int maxMastNr = -1;
LinkedList<CustMast> masts = new LinkedList<CustMast>();
Set<CustMast> set = refreshedLsa.getMasts();
Iterator<CustMast> iterMasts = set.iterator();
while (iterMasts.hasNext()) {
CustMast mast = (CustMast) iterMasts.next();
masts.add(mast);

int tmpNr = mast.getNr();
if (tmpNr > maxMastNr) {
maxMastNr = tmpNr;
}
}
parameter.put("aMaxMastNr", new Integer(maxMastNr));


jasperReport =
JasperCompileManager.compileReport("C:\ncset\workspace2.18\ch.bergauer.rcp.ncset\src\reportvorlagen\mastklemmen.xml"«»);

JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(masts);
jasperPrint = JasperManager.fillReport(jasperReport, parameter, ds);


JasperExportManager.exportReportToPdfFile(jasperPrint,
"C:\ncset\report\mastklemmen.pdf"«»);

tx.commit();
if (result == null) {
throw new DataException("Das Element existiert nicht mehr.", ""«»);
}

} catch (JRException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("ready"«»);

return result;
}

 

 

 

Code:
[code]
<?xml version="1.0" encoding="UTF-8" ?>
<!-- Created with iReport - A designer for JasperReports -->
<!DOCTYPE jasperReport PUBLIC "//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">
<jasperReport
name="mastklemmen"
columnCount="1"
printOrder="Vertical"
orientation="Landscape"
pageWidth="842"
pageHeight="595"
columnWidth="782"
columnSpacing="0"
leftMargin="30"
rightMargin="30"
topMargin="20"
bottomMargin="20"
whenNoDataType="NoPages"
isFloatColumnFooter="true"
isTitleNewPage="false"
isSummaryNewPage="false">
<property name="ireport.scriptlethandling" value="0" />
<property name="ireport.encoding" value="UTF-8" />
<import value="java.util.*" />
<import value="net.sf.jasperreports.engine.*" />
<import value="net.sf.jasperreports.engine.data.*" />

<subDataset name="SubDataset1" >


</subDataset>

<parameter name="aLsaNr" isForPrompting="false" class="java.lang.String"/>
<parameter name="SUBREPORT_DIR" isForPrompting="true" class="java.lang.String">
<property name="MASTID" value="$F(MAST).getId()" />
<defaultValueExpression ><![CDATA[".\reportvorlagen\"]]></defaultValueExpression>
</parameter>
<parameter name="aMaxMastNr" isForPrompting="false" class="java.lang.Integer"/>

<field name="fMast" class="ch.bergauer.rcp.ncset.ds.genbeans.CustMast"/>

<background>
<band height="0" isSplitAllowed="true" >
</band>
</background>
<title>
<band height="0" isSplitAllowed="true" >
</band>
</title>
<pageHeader>
<band height="27" isSplitAllowed="true" >
<staticText>
<reportElement
x="1"
y="0"
width="781"
height="26"
key="staticText"/>
<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
<textElement textAlignment="Center">
<font size="18"/>
</textElement>
<text><![CDATA[Mastklemmen]]></text>
</staticText>
</band>
</pageHeader>
<columnHeader>
<band height="0" isSplitAllowed="true" >
</band>
</columnHeader>
<detail>
<band height="96" isSplitAllowed="true" >
<staticText>
<reportElement
x="0"
y="0"
width="45"
height="19"
key="staticText-8"/>
<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
<textElement>
<font size="12"/>
</textElement>
<text><![CDATA[LSA:]]></text>
</staticText>
<textField isStretchWithOverflow="false" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement
x="45"
y="0"
width="27"
height="19"
key="textField-8"/>
<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
<textElement textAlignment="Right">
<font size="12"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$P{aLsaNr}]]></textFieldExpression>
</textField>
<staticText>
<reportElement
x="0"
y="19"
width="45"
height="19"
key="staticText-1"/>
<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
<textElement>
<font size="12"/>
</textElement>
<text><![CDATA[MastNr:]]></text>
</staticText>
<textField isStretchWithOverflow="false" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement
x="45"
y="19"
width="27"
height="19"
key="textField-1"/>
<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
<textElement textAlignment="Right">
<font size="12"/>
</textElement>
<textFieldExpression class="java.lang.Integer"><![CDATA[new Integer($F{fMast}.getNr())]]></textFieldExpression>
</textField>
<subreport isUsingCache="true">
<reportElement
x="1"
y="38"
width="781"
height="57"
key="subreport-1"/>
<subreportParameter name="MASTID">
<subreportParameterExpression><![CDATA[new Integer($F{fMast}.getId())]]></subreportParameterExpression>
</subreportParameter>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
<subreportExpression class="java.lang.String"><![CDATA[$P{SUBREPORT_DIR} + "mastklemmen_subreport0.jasper"]]></subreportExpression>
</subreport>
<break>
<reportElement
x="0"
y="95"
width="782"
height="0"
key="element-4">
<printWhenExpression><![CDATA[new Boolean(false == (new Integer($F{fMast}.getNr()).equals($P{aMaxMastNr})))]]></printWhenExpression>
</reportElement>
</break>
</band>
</detail>
<columnFooter>
<band height="0" isSplitAllowed="true" >
</band>
</columnFooter>
<pageFooter>
<band height="16" isSplitAllowed="true" >
<line direction="TopDown">
<reportElement
x="0"
y="0"
width="782"
height="0"
forecolor="#000000"
backcolor="#FFFFFF"
key="line-1"/>
<graphicElement stretchType="NoStretch"/>
</line>
<staticText>
<reportElement
x="1"
y="1"
width="90"
height="13"
key="staticText-6"/>
<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
<textElement>
<font/>
</textElement>
<text><![CDATA[Generiert am:]]></text>
</staticText>
<textField isStretchWithOverflow="false" pattern="EEEEE dd MMMMM yyyy" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement
x="91"
y="1"
width="209"
height="13"
forecolor="#000000"
key="textField-3"/>
<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
<textElement>
<font/>
</textElement>
<textFieldExpression class="java.util.Date"><![CDATA[new Date()]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="false" pattern="" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement
x="533"
y="1"
width="209"
height="13"
forecolor="#000000"
key="textField-2"/>
<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
<textElement textAlignment="Right">
<font/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA["Seite " + $V{PAGE_NUMBER} + " von "]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="false" pattern="" isBlankWhenNull="false" evaluationTime="Report" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement
mode="Transparent"
x="745"
y="1"
width="37"
height="13"
forecolor="#000000"
backcolor="#FFFFFF"
key="textField-10"/>
<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
<textElement textAlignment="Right">
<font size="10" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="false" isStrikeThrough="false" />
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA["" + $V{PAGE_NUMBER}]]></textFieldExpression>
</textField>
</band>
</pageFooter>
<lastPageFooter>
<band height="18" isSplitAllowed="true" >
<line direction="TopDown">
<reportElement
x="0"
y="0"
width="782"
height="0"
forecolor="#000000"
backcolor="#FFFFFF"
key="line-2"/>
<graphicElement stretchType="NoStretch"/>
</line>
<staticText>
<reportElement
x="0"
y="1"
width="90"
height="13"
key="staticText-7"/>
<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
<textElement>
<font/>
</textElement>
<text><![CDATA[Generiert am:]]></text>
</staticText>
<textField isStretchWithOverflow="false" pattern="EEEEE dd MMMMM yyyy" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement
x="91"
y="1"
width="209"
height="13"
forecolor="#000000"
key="textField-6"/>
<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
<textElement>
<font/>
</textElement>
<textFieldExpression class="java.util.Date"><![CDATA[new Date()]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="false" pattern="" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement
x="533"
y="1"
width="209"
height="13"
forecolor="#000000"
key="textField-9"/>
<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
<textElement textAlignment="Right">
<font/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA["Seite " + $V{PAGE_NUMBER} + " von "]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="false" pattern="" isBlankWhenNull="false" evaluationTime="Report" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement
mode="Transparent"
x="745"
y="1"
width="37"
height="13"
forecolor="#000000"
backcolor="#FFFFFF"
key="textField-11"/>
<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
<textElement textAlignment="Right">
<font size="10" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="false" isStrikeThrough="false" />
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA["" + $V{PAGE_NUMBER}]]></textFieldExpression>
</textField>
</band>
</lastPageFooter>
<summary>
<band height="50" isSplitAllowed="true" >
</band>
</summary>
</jasperReport>
:( :( :(
Link to comment
Share on other sites

  • 3 months later...
  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

I think that what you want to do is not used the Hibernate object as the field in your JRXML. Instead, try using the member variables from your object as the fields.

 

For example, if you have a bean that has properties a, b, and c, you would want your JRXML to contain fields named a, b, and c. That way, I understand it to be working, JasperReports will call the getter method of each field listed in the JRXML on whatever the data source you pass into it is.

 

In your code, instead of putting in

Code:
<field name="fMast" class="ch.bergauer.rcp.ncset.ds.genbeans.CustMast"/>

 

You should put in a field for each part of the CustMast object that you wish to access. For example:

Code:
[code]<field name="nr" class="java.lang.Integer" />

 

Then reference these fields directly in the rest of your JRXML like:

Code:
[code]<textFieldExpression class="java.lang.Integer">$F{nr}</textFieldExpression>
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...