简体   繁体   English

从查询中获取值,该查询在jasper报告中检索两个实体

[英]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: 我将ireport 4.1.1与hibernate jpa一起使用,并且我有一个查询可检索两个实体:

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: 我试图获取a和b的值,在java中,它返回一个包含两个项目的对象数组(Object []),但是当我尝试在jasper报告中执行此操作时,它给了我这个错误:

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??? 我认为我只需要将fieldName替换为将要返回的对象的名称,但是我不知道并且我试图找到它,但是我没有成功,任何人都可以帮助我吗?

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. 该错误是因为您的数据未使用bean属性映射,或者您可以认为数据模式不符合bean属性。 I was having the same problem in my java project. 我的java项目中遇到了同样的问题。 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 然后我整理出您的数据应采用正确的2D数组形式,然后我从某处获取了样本数据并执行了此操作

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. 您的字段名称应以小写字母开头,此外,该字段名称应与该数据内ur提供的列名称一样小。

Hope this will help you. 希望这会帮助你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM