brouardbas Posted September 8, 2011 Share Posted September 8, 2011 hi,in my application, I use JasperReports library 4.1.1 to make reporting. I use hibernate connection and hql query. I want display in previewer a single page. So I want JasperReports to fill report on only one page. For that I write following source code :But the parameter code "parameters.put(JRHibernateQueryExecuterFactory.PROPERTY_HIBERNATE_QUERY_LIST_PAGE_SIZE, 1);" is not read because I have all filled pages.I saw in JRXML that the tag "<property name="net.sf.jasperreports.hql.query.list.page.size" value="1"/>" is missing. Thank for your help. P.S : sorry for my bad english languageCode: /** * This method is used to fill a report and to show if an error occurred during the filling */ public void fillReport() { logger.trace("filling of report"); reportPrinted = null; JasperReport reportCompiled = getReportCompiled(); Session session = HibernateUtil.getSessionFactory().getCurrentSession(); Transaction transaction = session.beginTransaction(); Map<String, Object> reportParameters = getFillingReportParameters(session); try { reportPrinted = JasperFillManager.fillReport(reportCompiled, reportParameters); logger.trace("filling report done and it contains {} pages", getNumberOfPages()); } catch (JRException e) { logger.error("An error is occured while filling of report : {}", LoggerManager.getErrorMessage(e)); } transaction.rollback(); } /** * @param session * the hibernate session * @return the map of filling report parameters */ private Map<String, Object> getFillingReportParameters(Session session) { Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put(JRHibernateQueryExecuterFactory.PARAMETER_HIBERNATE_SESSION, session); parameters.put(JRHibernateQueryExecuterFactory.PROPERTY_HIBERNATE_QUERY_RUN_TYPE, JRHibernateQueryExecuterFactory.VALUE_HIBERNATE_QUERY_RUN_TYPE_LIST); parameters.put(JRHibernateQueryExecuterFactory.PROPERTY_HIBERNATE_QUERY_LIST_PAGE_SIZE, 1); return parameters; } Link to comment Share on other sites More sharing options...
szaharia Posted September 9, 2011 Share Posted September 9, 2011 Hi,There is no builtin parameter related to the JRHibernateQueryExecuterFactory.PROPERTY_HIBERNATE_QUERY_LIST_PAGE_SIZE property. The solution is either to set this property in the JRXML file, or to set it in the jasperreports.properties file.HTH,sanda Link to comment Share on other sites More sharing options...
brouardbas Posted September 9, 2011 Author Share Posted September 9, 2011 Code:thanks you for your reply, but I try to set the property with the following code : jasperDesignReport.setProperty("net.sf.jasperreports.hql.query.list.page.size", "1"); I have the tag in the JRXML but JasperReports continue to fill all pages. Link to comment Share on other sites More sharing options...
lucianc Posted September 9, 2011 Share Posted September 9, 2011 brouardbasWrote: But the parameter code "parameters.put(JRHibernateQueryExecuterFactory.PROPERTY_HIBERNATE_QUERY_LIST_PAGE_SIZE, 1);" is not read because I have all filled pages. If you go at http://jasperreports.sourceforge.net/api/net/sf/jasperreports/engine/query/JRHibernateQueryExecuterFactory.html#PROPERTY_HIBERNATE_QUERY_LIST_PAGE_SIZE and read what that property is used for, you'll find out that it has nothing to do with report pages.If you want to fill the report in a single page, use JRParameter.html.IS_IGNORE_PAGINATIONRegards,Lucian Link to comment Share on other sites More sharing options...
brouardbas Posted September 9, 2011 Author Share Posted September 9, 2011 Code:Thank you for your reply, but I don't want to remove pagination, I want to limit the number of results at 100 for exemple. In SQL, we use instruction "limit 100" but it doesn't exist in hql. With hibernate we can just use the instruction query.maxResult(100) but this is JasperReports that manage query execution so I can't use it. How do you limit the number of results with JasperReports using hql query ? Thank you Link to comment Share on other sites More sharing options...
lucianc Posted September 9, 2011 Share Posted September 9, 2011 Use JRParameter.html.REPORT_MAX_COUNT for that. Post Edited by lucianc at 09/09/2011 16:47 Link to comment Share on other sites More sharing options...
brouardbas Posted September 9, 2011 Author Share Posted September 9, 2011 Code:thanks indeed it works but as regards the execution duration, I think the limit only impact on displaying data and not on amount of data retrieved by hql query. Link to comment Share on other sites More sharing options...
lucianc Posted September 9, 2011 Share Posted September 9, 2011 If you want to see what exactly happens, I suggest enabling debug logging for Hibernate. Link to comment Share on other sites More sharing options...
brouardbas Posted September 9, 2011 Author Share Posted September 9, 2011 Indeed after seen hibernate logs, the limit impact on execution query. Thanks you again for you help. 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