I get this error when I try to use listaRelatorio with sqlquery or HLQ query
ERROR:
Code:
Grave: net.sf.jasperreports.engine.JRException: Error retrieving field value from bean : username
at net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getBeanProperty(JRAbstractBeanDataSource.java:123)
at net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getFieldValue(JRAbstractBeanDataSource.java:96)
at net.sf.jasperreports.engine.data.JRBeanCollectionDataSource.getFieldValue(JRBeanCollectionDataSource.java:100)
Caused by: java.lang.NoSuchMethodException: Unknown property 'username' on class 'class [Ljava.lang.Object;'
Code:
public List listaRelatorio() {
session = HibernateUtil.getSession();
SQLQuery sqlquery = session.createSQLQuery("SELECT u.username, u.name, t.team FROM usuario u "
+ "INNER JOIN team t ON u.id_team = t.id_team ORDER BY name ASC");
List listaUs = sqlquery.list();
return listaUs;
}
Code:
public List listaRelatorio(){
session = HibernateUtil.getSession();
Query query = session.createQuery("SELECT u.username, u.name, t.team FROM Usuario u INNER JOIN u.team as t");
List listaUs = query.list();
return listaUs;
}
Code:
// **************** Reports **************** //
public void reportBuilder() throws JRException {
UsuarioDao usuarioDao = new UsuarioDaoImpl();
List listaUs = usuarioDao.listaRelatorio();
JRBeanCollectionDataSource beanCollectionDataSource = new JRBeanCollectionDataSource(listaUs);
String report = FacesContext.getCurrentInstance().getExternalContext().getRealPath("/reports/users.jasper");
jasperPrint = JasperFillManager.fillReport(report, new HashMap(), beanCollectionDataSource);
}
public void exportToPdf(ActionEvent actionEvent) throws JRException, IOException {
reportBuilder();
HttpServletResponse httpServletResponse = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
httpServletResponse.addHeader("Content-disposition", "attachment; filename=users.pdf");
ServletOutputStream servletStream = httpServletResponse.getOutputStream();
JasperExportManager.exportReportToPdfStream(jasperPrint, servletStream);
FacesContext.getCurrentInstance().responseComplete();
}