net.sf.jasperreports.engine.JRException: Error retrieving field value from bean: fullname. When using NativeQuery

Getting:  

   

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

Only when using `NativeQuery` in `Hibernate` with `JasperReports`.

When I use JPA criteria query then there's no issue

**JPA Criteria**

 try (Session session = sessionFactory.openSession()) {
        CriteriaBuilder criteriaBuilder = session.getCriteriaBuilder();
        CriteriaQuery Client criteriaQuery = criteriaBuilder.createQuery(Client.class);
        Root root = criteriaQuery.from(Client.class);
        criteriaQuery.where(criteriaBuilder.equal(root.get("id"), id));
        return session.createQuery(criteriaQuery).getResultList();
    }

But when I use NativeQuery I face
`net.sf.jasperreports.engine.JRException: Error retrieving field value from bean: fullname.`

<b>Native Query :</b>

 try (Session session = sessionFactory.openSession()) {
        List<Client> query = session.createNativeQuery("select c.*, p.*
            from client c join product p on c.pid = p.id where c.id = :id")
            .addEntity("c", Client.class).addJoin("p", "c.product")
            .setParameter("id", id).list();
        return query;
    }


Here Jasper JRXML

<?xml version="1.0" encoding="UTF-8"?>
    <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="Quotation" pageWidth="595" pageHeight="600" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="3954e5eb-656a-454e-b9e5-35f7e5262d48">
        <property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
        <property name="ireport.zoom" value="1.0"/>
        <property name="ireport.x" value="0"/>
        <property name="ireport.y" value="0"/>
        <field name="fullname" class="java.lang.String"/>
        <field name="mobile" class="java.lang.String"/>
        <field name="city" class="java.lang.String"/>
        <field name="address" class="java.lang.String"/>
        <field name="quotationNo" class="java.lang.String"/>
        <field name="valid" class="java.lang.String"/>
        <field name="product.description" class="java.lang.String"/>
        <field name="product.cost" class="java.lang.String"/>
        <field name="product.name" class="java.lang.String"/>


Client.java:

public class Client  implements java.io.Serializable {
 
 
     private Integer id;
     private Product product;
     private String fullname;
     private String business;
     private String address;
     private String city;
     private String mobile;
     private String addedBy;
     private String date;
     private String status;
     private String quotationNo;
     private String valid;
     private String productName;
     private Set orderses = new HashSet(0);
 
    public String getFullname() {
        return this.fullname;
    }
 
    public void setFullname(String fullname) {
        this.fullname = fullname;
    }  

I've already removed

<FieldDescription>

from fields in Jasper JRXML

I also tried passing and removing false parameter in
new JRBeanColllectionDataSource(collection, false);
new JRBeanColllectionDataSource(collection);

Passing `"false" parameter` only works for `JPA criteria` for `Native query` it doesn't matter whether parameter is passed or not it gives

    net.sf.jasperreports.engine.JRException: Error retrieving field value from bean: fullname.  
swapnilnagtilak722's picture
Joined: Apr 6 2019 - 7:59am
Last seen: 1 year 4 months ago

0 Answers:

No answers yet
Feedback