swapnilnagtilak722 Posted September 6, 2020 Share Posted September 6, 2020 Getting: net.sf.jasperreports.engine.JRException: Error retrieving field value from bean: fullname.[/code] 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(); }[/code]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; }[/code] 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"/>[/code]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; } [/code]I've already removed<FieldDescription>[/code]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. [/code] Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now