-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: HLQ x SQL
PostPosted: Tue Apr 05, 2016 11:11 am 
Newbie

Joined: Tue Mar 15, 2016 4:10 pm
Posts: 6
Hi everyone.

I'm trying to create a HLQ query using my SQL example, but I can't create.
Your help is appreciable.
Thanks

SQL:
Code:
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


HLQ:
Code:
SELECT u.username, u.name, t.team FROM Usuario u INNER JOIN u.team as t ORDERY BY u.name ASC


Top
 Profile  
 
 Post subject: Re: HLQ x SQL
PostPosted: Tue Apr 05, 2016 2:01 pm 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
The query is fine, what exactly is not working?


Top
 Profile  
 
 Post subject: Re: HLQ x SQL
PostPosted: Thu Apr 07, 2016 6:58 pm 
Newbie

Joined: Tue Mar 15, 2016 4:10 pm
Posts: 6
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();
     }


Top
 Profile  
 
 Post subject: Re: HLQ x SQL
PostPosted: Fri Apr 08, 2016 12:58 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
That's because you are fetching a projection which you don't further transform to a DTO.
Create a DTO with these properties: username, name, team and provide a ResultTransormer as explained in the User Guide.


Top
 Profile  
 
 Post subject: [Resolved ]Re: HLQ x SQL
PostPosted: Sat Apr 09, 2016 10:04 pm 
Newbie

Joined: Tue Mar 15, 2016 4:10 pm
Posts: 6
Resolved.

Changed from HLQ to SQL:

Code:
//JDBC
Conexao conn = new Conexao();
String report = FacesContext.getCurrentInstance().getExternalContext().getRealPath("/reports/users.jrxml"); //Use jrxml, not .jasper
JasperReport pathjrxml = JasperCompileManager.compileReport(report);
jasperPrint = JasperFillManager.fillReport(pathjrxml, null, conn.getConn()); //getting JDBC connection


Code:
//list HLQ
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);


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.