简体   繁体   中英

Getting values from a query that retrieves two entites in jasper reports

i am using ireport 4.1.1 with hibernate jpa and I have a query that retrieves two entities:

select a,b from TableA a left join a.tableBList b

I am trying to get the value of a and b, in java, it returns an array of objects (Object[]) with two items, but when I try to do this on jasper reports it gives me this error:

Exception in thread "main" net.sf.jasperreports.engine.JRRuntimeException: net.sf.jasperreports.engine.JRException: Error retrieving field value from bean : fieldName

I think that i only need to replace fieldName with the name of the object that will be returned but I don'w know it and I have tried to find it but I have had no success, anyone of you can help me please???

Thanks in advance :)

This error is because your data is not mapping with beans property, or you can that your data pattern is not according to the beans property. I was having the same problem in my java project. And I sorted out that your data should be in a proper 2D array form, then I took sample data from somewhere and did this

String[][] data =
{{ "N263Y", "T-11", " 39 ROSCOE TRNR RACER"},
{ "N4087X", "BA100-163", "BRADLEY AEROBAT"},
{ "N43JE", "HAYABUSA 1", "NAKAJIMA KI-43 IIIA"},
{ "N912S", "9973CC", "PA18-150"}};

        JTable m = new JTable(data,headers);
try {

            JasperReport jasperReport = JasperCompileManager.compileReport(fileName);

            if(jasperReport != null )
               System.out.println("so far so good ");

            // Fill the report using an empty data source

            JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, new JRTableModelDataSource(m.getModel()) );//create());//con.connection);
            try{
            JasperExportManager.exportReportToPdfFile(jasperPrint, outFileName);
            System.out.printf("File exported sucessfully");
            }catch(Exception e){
                e.printStackTrace();
            }
            JasperViewer.viewReport(jasperPrint);

        } catch (JRException e) {
            JOptionPane.showMessageDialog(null, e);
            e.printStackTrace();
            System.exit(1);
        }

Note:

Your field name should start with small letters, moreover field names should be small as of the columns names ur providing within that data.

Hope this will help you.

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